spatial_extent.py 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. """!@package grass.temporal
  2. @brief GRASS Python scripting module (temporal GIS functions)
  3. Temporal GIS related spatial extent functions to be used in Python scripts and tgis packages.
  4. Usage:
  5. @code
  6. import grass.temporal as tgis
  7. extent = tgis.raster_spatial_extent()
  8. ...
  9. @endcode
  10. (C) 2008-2011 by the GRASS Development Team
  11. This program is free software under the GNU General Public
  12. License (>=v2). Read the file COPYING that comes with GRASS
  13. for details.
  14. @author Soeren Gebbert
  15. """
  16. from base import *
  17. class spatial_extent(sql_database_interface):
  18. """!This is the spatial extent base class for all maps and space time datasets"""
  19. def __init__(self, table=None, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None, proj="XY"):
  20. sql_database_interface.__init__(self, table, ident)
  21. self.set_id(ident)
  22. self.set_spatial_extent(north, south, east, west, top, bottom)
  23. self.set_projection(proj)
  24. def overlapping_2d(self, extent):
  25. """!Return True if the two dimensional extents overlap. Code is lend from wind_overlap.c in lib/gis
  26. Overlapping includes the spatial relations:
  27. * contain
  28. * in
  29. * cover
  30. * covered
  31. * equivalent
  32. """
  33. if self.get_projection() != extent.get_projection():
  34. core.error(_("Projections are different. Unable to compute overlapping_2d for spatial extents"))
  35. return False
  36. N = extent.get_north()
  37. S = extent.get_south()
  38. E = extent.get_east()
  39. W = extent.get_west()
  40. # Adjust the east and west in case of LL projection
  41. if self.get_projection() == "LL":
  42. while E < self.get_west():
  43. E += 360.0
  44. W += 360.0
  45. while W > self.get_east():
  46. E -= 360.0
  47. W -= 360.0
  48. if(self.get_north() <= S):
  49. return False
  50. if(self.get_south() >= N):
  51. return False
  52. if self.get_east() <= W:
  53. return False
  54. if self.get_west() >= E:
  55. return False
  56. return True
  57. def overlapping(self, extent):
  58. """!Return True if the three dimensional extents overlap
  59. Overlapping includes the spatial relations:
  60. * contain
  61. * in
  62. * cover
  63. * covered
  64. * equivalent
  65. """
  66. if not self.overlapping_2d(extent):
  67. return False
  68. T = extent.get_top()
  69. B = extent.get_bottom()
  70. if self.get_top() <= B:
  71. return False
  72. if self.get_bottom() >= T:
  73. return False
  74. return True
  75. def intersect_2d(self, extent):
  76. """!Return the two dimensional intersection as spatial_extent object or None
  77. in case no intersection was found.
  78. """
  79. if not self.overlapping_2d(extent):
  80. return None
  81. eN = extent.get_north()
  82. eS = extent.get_south()
  83. eE = extent.get_east()
  84. eW = extent.get_west()
  85. N = self.get_north()
  86. S = self.get_south()
  87. E = self.get_east()
  88. W = self.get_west()
  89. # Adjust the east and west in case of LL projection
  90. if self.get_projection() == "LL":
  91. while eE < W:
  92. eE += 360.0
  93. eW += 360.0
  94. while eW > E:
  95. eE -= 360.0
  96. eW -= 360.0
  97. # Compute the extent
  98. nN = N
  99. nS = S
  100. nE = E
  101. nW = W
  102. if W < eW:
  103. nW = eW
  104. if E > eE:
  105. nE = eE
  106. if N > eN:
  107. nN = eN
  108. if S < eS:
  109. nS = eS
  110. new = spatial_extent(north=nN, south=nS, east=nE, west=nW, top=0, bottom=0, proj=self.get_projection())
  111. return new
  112. def intersect(self, extent):
  113. """!Return the three dimensional intersection as spatial_extent object or None
  114. in case no intersection was found.
  115. """
  116. if not self.overlapping(extent):
  117. return None
  118. new = self.intersect_2d(extent)
  119. eT = extent.get_top()
  120. eB = extent.get_bottom()
  121. T = self.get_top()
  122. B = self.get_bottom()
  123. nT = T
  124. nB = B
  125. if B < eB:
  126. nB = eB
  127. if T > eT:
  128. nT = eT
  129. new.set_top(nT)
  130. new.set_bottom(nB)
  131. return new
  132. def is_in_2d(self, extent):
  133. """Check two dimensional if the self is located in extent
  134. _____
  135. |A _ |
  136. | |_| |
  137. |_____|
  138. """
  139. if self.get_projection() != extent.get_projection():
  140. core.error(_("Projections are different. Unable to compute is_in_2d for spatial extents"))
  141. return False
  142. eN = extent.get_north()
  143. eS = extent.get_south()
  144. eE = extent.get_east()
  145. eW = extent.get_west()
  146. N = self.get_north()
  147. S = self.get_south()
  148. E = self.get_east()
  149. W = self.get_west()
  150. # Adjust the east and west in case of LL projection
  151. if self.get_projection() == "LL":
  152. while eE < W:
  153. eE += 360.0
  154. eW += 360.0
  155. while eW > E:
  156. eE -= 360.0
  157. eW -= 360.0
  158. if W <= eW:
  159. return False
  160. if E >= eE:
  161. return False
  162. if N >= eN:
  163. return False
  164. if S <= eS:
  165. return False
  166. return True
  167. def is_in(self, extent):
  168. """Check three dimensional if the self is located in extent """
  169. if not self.is_in_2d(extent):
  170. return False
  171. eT = extent.get_top()
  172. eB = extent.get_bottom()
  173. T = self.get_top()
  174. B = self.get_bottom()
  175. if B <= eB:
  176. return False
  177. if T >= eT:
  178. return False
  179. return True
  180. def contain_2d(self, extent):
  181. """Check two dimensional if self contains extent """
  182. return extent.is_in_2d(self)
  183. def contain(self, extent):
  184. """Check three dimensional if self contains extent """
  185. return extent.is_in(self)
  186. def equivalent_2d(self, extent):
  187. """Check two dimensional if self is equivalent to extent """
  188. if self.get_projection() != extent.get_projection():
  189. core.error(_("Projections are different. Unable to compute equivalent_2d for spatial extents"))
  190. return False
  191. eN = extent.get_north()
  192. eS = extent.get_south()
  193. eE = extent.get_east()
  194. eW = extent.get_west()
  195. N = self.get_north()
  196. S = self.get_south()
  197. E = self.get_east()
  198. W = self.get_west()
  199. # Adjust the east and west in case of LL projection
  200. if self.get_projection() == "LL":
  201. while eE < W:
  202. eE += 360.0
  203. eW += 360.0
  204. while eW > E:
  205. eE -= 360.0
  206. eW -= 360.0
  207. if W != eW:
  208. return False
  209. if E != eE:
  210. return False
  211. if N != eN:
  212. return False
  213. if S != eS:
  214. return False
  215. return True
  216. def equivalent(self, extent):
  217. """Check three dimensional if self is equivalent to extent """
  218. if not self.equivalent_2d(extent):
  219. return False
  220. eT = extent.get_top()
  221. eB = extent.get_bottom()
  222. T = self.get_top()
  223. B = self.get_bottom()
  224. if B != eB:
  225. return False
  226. if T != eT:
  227. return False
  228. return True
  229. def cover_2d(self, extent):
  230. """Return True if two dimensional self covers extent
  231. _____ _____ _____ _____
  232. |A __| |__ A| |A | B| |B | A|
  233. | |B | | B| | | |__| |__| |
  234. |__|__| |__|__| |_____| |_____|
  235. _____ _____ _____ _____
  236. |A|B| | |A __| |A _ | |__ A|
  237. | |_| | | |__|B | |B| | B|__| |
  238. |_____| |_____| |_|_|_| |_____|
  239. _____ _____ _____ _____
  240. |A|B | |_____|A |A|B|A| |_____|A
  241. | | | |B | | | | | |_____|B
  242. |_|___| |_____| |_|_|_| |_____|A
  243. The following cases are excluded:
  244. * contain
  245. * in
  246. * equivalent
  247. """
  248. if self.get_projection() != extent.get_projection():
  249. core.error(_("Projections are different. Unable to compute cover_2d for spatial extents"))
  250. return False
  251. # Exclude equivalent_2d
  252. if self.equivalent_2d(extent):
  253. return False
  254. eN = extent.get_north()
  255. eS = extent.get_south()
  256. eE = extent.get_east()
  257. eW = extent.get_west()
  258. N = self.get_north()
  259. S = self.get_south()
  260. E = self.get_east()
  261. W = self.get_west()
  262. # Adjust the east and west in case of LL projection
  263. if self.get_projection() == "LL":
  264. while eE < W:
  265. eE += 360.0
  266. eW += 360.0
  267. while eW > E:
  268. eE -= 360.0
  269. eW -= 360.0
  270. # Edges of extent located outside of self are not allowed
  271. if E < eW:
  272. return False
  273. if W > eE:
  274. return False
  275. if N < eS:
  276. return False
  277. if S > eN:
  278. return False
  279. # First we check that at least one edge of extent meets an edge of self
  280. if W != eW and E != eE and N != eN and S != eS:
  281. return False
  282. # We check that at least one edge of extent is located in self
  283. edge_count = 0
  284. if W < eW and E > eW:
  285. edge_count += 1
  286. if E > eE and W < eE:
  287. edge_count += 1
  288. if N > eN and S < eN:
  289. edge_count += 1
  290. if S < eS and N > eS:
  291. edge_count += 1
  292. if edge_count == 0:
  293. return False
  294. return True
  295. def cover(self, extent):
  296. """Return True if three dimensional self covers extent
  297. The following cases are excluded:
  298. * contain
  299. * in
  300. * equivalent
  301. """
  302. if self.get_projection() != extent.get_projection():
  303. core.error(_("Projections are different. Unable to compute cover for spatial extents"))
  304. return False
  305. # Exclude equivalent_2d
  306. if self.equivalent_2d(extent):
  307. return False
  308. eN = extent.get_north()
  309. eS = extent.get_south()
  310. eE = extent.get_east()
  311. eW = extent.get_west()
  312. eT = extent.get_top()
  313. eB = extent.get_bottom()
  314. N = self.get_north()
  315. S = self.get_south()
  316. E = self.get_east()
  317. W = self.get_west()
  318. T = self.get_top()
  319. B = self.get_bottom()
  320. # Adjust the east and west in case of LL projection
  321. if self.get_projection() == "LL":
  322. while eE < W:
  323. eE += 360.0
  324. eW += 360.0
  325. while eW > E:
  326. eE -= 360.0
  327. eW -= 360.0
  328. # Edges of extent located outside of self are not allowed
  329. if E <= eW:
  330. return False
  331. if W >= eE:
  332. return False
  333. if N <= eS:
  334. return False
  335. if S >= eN:
  336. return False
  337. if T <= eB:
  338. return False
  339. if B >= eT:
  340. return False
  341. # First we check that at least one edge of extent meets an edge of self
  342. if W != eW and E != eE and N != eN and S != eS and B != eB and T != eT:
  343. return False
  344. # We check that at least one edge of extent is located in self
  345. edge_count = 0
  346. if W < eW and E > eW:
  347. edge_count += 1
  348. if E > eE and W < eE:
  349. edge_count += 1
  350. if N > eN and S < eN:
  351. edge_count += 1
  352. if S < eS and N > eS:
  353. edge_count += 1
  354. if N > eN and S < eN:
  355. edge_count += 1
  356. if S < eS and N > eS:
  357. edge_count += 1
  358. if T > eT and B < eT:
  359. edge_count += 1
  360. if B < eB and T > eB:
  361. edge_count += 1
  362. if edge_count == 0:
  363. return False
  364. return True
  365. def covered_2d(self, extent):
  366. """Check two dimensional if self is covered by extent """
  367. return extent.cover_2d(self)
  368. def covered(self, extent):
  369. """Check three dimensional if self is covered by extent """
  370. return extent.cover(self)
  371. def overlap_2d(self, extent):
  372. """Return True if the two dimensional extents overlap. Code is lend from wind_overlap.c in lib/gis
  373. _____
  374. |A __|__
  375. | | | B|
  376. |__|__| |
  377. |_____|
  378. The following cases are excluded:
  379. * contain
  380. * in
  381. * cover
  382. * covered
  383. * equivalent
  384. """
  385. if self.contain_2d(extent):
  386. return False
  387. if self.is_in_2d(extent):
  388. return False
  389. if self.cover_2d(extent):
  390. return False
  391. if self.covered_2d(extent):
  392. return False
  393. if self.equivalent_2d(extent):
  394. return False
  395. N = extent.get_north()
  396. S = extent.get_south()
  397. E = extent.get_east()
  398. W = extent.get_west()
  399. # Adjust the east and west in case of LL projection
  400. if self.get_projection() == "LL":
  401. while E < self.get_west():
  402. E += 360.0
  403. W += 360.0
  404. while W > self.get_east():
  405. E -= 360.0
  406. W -= 360.0
  407. if(self.get_north() <= S):
  408. return False
  409. if(self.get_south() >= N):
  410. return False
  411. if self.get_east() <= W:
  412. return False
  413. if self.get_west() >= E:
  414. return False
  415. return True
  416. def overlap(self, extent):
  417. """Return True if the three dimensional extents overlap
  418. The following cases are excluded:
  419. * contain
  420. * in
  421. * cover
  422. * covered
  423. * equivalent
  424. """
  425. if self.is_in(extent):
  426. return False
  427. if self.contain(extent):
  428. return False
  429. if self.cover(extent):
  430. return False
  431. if self.covered(extent):
  432. return False
  433. if self.equivalent(extent):
  434. return False
  435. N = extent.get_north()
  436. S = extent.get_south()
  437. E = extent.get_east()
  438. W = extent.get_west()
  439. T = extent.get_top()
  440. B = extent.get_bottom()
  441. # Adjust the east and west in case of LL projection
  442. if self.get_projection() == "LL":
  443. while E < self.get_west():
  444. E += 360.0
  445. W += 360.0
  446. while W > self.get_east():
  447. E -= 360.0
  448. W -= 360.0
  449. if(self.get_north() <= S):
  450. return False
  451. if(self.get_south() >= N):
  452. return False
  453. if self.get_east() <= W:
  454. return False
  455. if self.get_west() >= E:
  456. return False
  457. if self.get_top() <= B:
  458. return False
  459. if self.get_bottom() >= T:
  460. return False
  461. return True
  462. def meet_2d(self,extent):
  463. """ Check if self and extent meet each other in two dimensions
  464. _____ _____ _____ _____
  465. | A | B | | B | A |
  466. |_____| | | | |
  467. |_____| |_____|_____|
  468. ___
  469. | A |
  470. | |
  471. |___| _____
  472. | B | | B |
  473. | | | |
  474. |_____| |_____|_
  475. | A |
  476. | |
  477. |_____|
  478. """
  479. eN = extent.get_north()
  480. eS = extent.get_south()
  481. eE = extent.get_east()
  482. eW = extent.get_west()
  483. eT = extent.get_top()
  484. eB = extent.get_bottom()
  485. N = self.get_north()
  486. S = self.get_south()
  487. E = self.get_east()
  488. W = self.get_west()
  489. # Adjust the east and west in case of LL projection
  490. if self.get_projection() == "LL":
  491. while eE < W:
  492. eE += 360.0
  493. eW += 360.0
  494. while eW > E:
  495. eE -= 360.0
  496. eW -= 360.0
  497. edge = None
  498. edge_count = 0
  499. if E == eW:
  500. edge = "E"
  501. edge_count += 1
  502. if W == eE:
  503. edge = "W"
  504. edge_count += 1
  505. if N == eS:
  506. edge = "N"
  507. edge_count += 1
  508. if S == eN:
  509. edge = "S"
  510. edge_count += 1
  511. # Meet a a single edge only
  512. if edge_count != 1:
  513. return False
  514. # Check boundaries of the faces
  515. if edge == "E" or edge == "W":
  516. if N < eS or S > eN:
  517. return False
  518. if edge == "N" or edge == "S":
  519. if E < eW or W > eE:
  520. return False
  521. return True
  522. def meet(self,extent):
  523. """ Check if self and extent meet other in three dimensions"""
  524. eN = extent.get_north()
  525. eS = extent.get_south()
  526. eE = extent.get_east()
  527. eW = extent.get_west()
  528. eT = extent.get_top()
  529. eB = extent.get_bottom()
  530. N = self.get_north()
  531. S = self.get_south()
  532. E = self.get_east()
  533. W = self.get_west()
  534. T = self.get_top()
  535. B = self.get_bottom()
  536. # Adjust the east and west in case of LL projection
  537. if self.get_projection() == "LL":
  538. while eE < W:
  539. eE += 360.0
  540. eW += 360.0
  541. while eW > E:
  542. eE -= 360.0
  543. eW -= 360.0
  544. edge = None
  545. edge_count = 0
  546. if E == eW:
  547. edge = "E"
  548. edge_count += 1
  549. if W == eE:
  550. edge = "W"
  551. edge_count += 1
  552. if N == eS:
  553. edge = "N"
  554. edge_count += 1
  555. if S == eN:
  556. edge = "S"
  557. edge_count += 1
  558. if T == eB:
  559. edge = "T"
  560. edge_count += 1
  561. if B == eT:
  562. edge = "B"
  563. edge_count += 1
  564. # Meet a single edge only
  565. if edge_count != 1:
  566. return False
  567. # Check boundaries of the faces
  568. if edge == "E" or edge == "W":
  569. if N < eS or S > eN:
  570. return False
  571. if T < eB or B > eT:
  572. return False
  573. if edge == "N" or edge == "S":
  574. if E < eW or W > eE:
  575. return False
  576. if T < eB or B > eT:
  577. return False
  578. if edge == "T" or edge == "B":
  579. if E < eW or W > eE:
  580. return False
  581. if N < eS or S > eN:
  582. return False
  583. return True
  584. def disjoint_2d(self, extent):
  585. """Return True if the two dimensional extents are disjoint
  586. """
  587. if self.overlapping_2d(extent) or self.meet_2d(extent):
  588. return False
  589. return True
  590. def disjoint(self, extent):
  591. """Return True if the three dimensional extents are disjoint
  592. """
  593. if self.overlapping(extent) or self.meet(extent):
  594. return False
  595. return True
  596. def spatial_relation_2d(self, extent):
  597. """Returns the two dimensional spatial relation between self and extent
  598. Spatial relations are:
  599. * disjoint
  600. * meet
  601. * overlap
  602. * cover
  603. * covered
  604. * in
  605. * contain
  606. * equivalent
  607. """
  608. if self.equivalent_2d(extent):
  609. return "equivalent"
  610. if self.contain_2d(extent):
  611. return "contain"
  612. if self.is_in_2d(extent):
  613. return "in"
  614. if self.cover_2d(extent):
  615. return "cover"
  616. if self.covered_2d(extent):
  617. return "covered"
  618. if self.overlap_2d(extent):
  619. return "overlap"
  620. if self.meet_2d(extent):
  621. return "meet"
  622. if self.disjoint_2d(extent):
  623. return "disjoint"
  624. return "unknown"
  625. def spatial_relation(self, extent):
  626. """Returns the three dimensional spatial relation between self and extent
  627. Spatial relations are:
  628. * disjoint
  629. * meet
  630. * overlap
  631. * cover
  632. * covered
  633. * in
  634. * contain
  635. * equivalent
  636. """
  637. if self.equivalent(extent):
  638. return "equivalent"
  639. if self.contain(extent):
  640. return "contain"
  641. if self.is_in(extent):
  642. return "in"
  643. if self.cover(extent):
  644. return "cover"
  645. if self.covered(extent):
  646. return "covered"
  647. if self.overlap(extent):
  648. return "overlap"
  649. if self.meet(extent):
  650. return "meet"
  651. if self.disjoint(extent):
  652. return "disjoint"
  653. return "unknown"
  654. def set_spatial_extent(self, north, south, east, west, top, bottom):
  655. """Set the spatial extent"""
  656. self.set_north(north)
  657. self.set_south(south)
  658. self.set_east(east)
  659. self.set_west(west)
  660. self.set_top(top)
  661. self.set_bottom(bottom)
  662. def set_projection(self, proj):
  663. """Set the projection of the spatial extent it should be XY or LL.
  664. As default the projection is XY
  665. """
  666. if proj == None or (proj != "XY" and proj != "LL"):
  667. self.D["proj"] = "XY"
  668. else:
  669. self.D["proj"] = proj
  670. def set_spatial_extent_2d(self, north, south, east, west):
  671. self.set_id(ident)
  672. self.set_north(north)
  673. self.set_south(south)
  674. self.set_east(east)
  675. self.set_west(west)
  676. self.set_top(0)
  677. self.set_bottom(0)
  678. def set_id(self, ident):
  679. """Convenient method to set the unique identifier (primary key)"""
  680. self.ident = ident
  681. self.D["id"] = ident
  682. def set_north(self, north):
  683. """Set the northern edge of the map"""
  684. self.D["north"] = north
  685. def set_south(self, sourth):
  686. """Set the southern edge of the map"""
  687. self.D["south"] = sourth
  688. def set_west(self, west):
  689. """Set the western edge of the map"""
  690. self.D["west"] = west
  691. def set_east(self, east):
  692. """Set the eastern edge of the map"""
  693. self.D["east"] = east
  694. def set_top(self, top):
  695. """Set the top edge of the map"""
  696. self.D["top"] = top
  697. def set_bottom(self, bottom):
  698. """Set the bottom edge of the map"""
  699. self.D["bottom"] = bottom
  700. def get_id(self):
  701. """Convenient method to get the unique identifier (primary key)
  702. @return None if not found
  703. """
  704. if self.D.has_key("id"):
  705. return self.D["id"]
  706. else:
  707. return None
  708. def get_projection(self):
  709. """Get the projection of the spatial extent"""
  710. return self.D["proj"]
  711. def get_volume(self):
  712. """Compute the volume of the extent, in case z is zero (top == bottom or top - bottom = 1) the area is returned"""
  713. if self.get_projection() == "LL":
  714. core.error(_("Volume computation is not supported for LL projections"))
  715. area = self.get_area()
  716. bbox = self.get_spatial_extent()
  717. z = abs(bbox[4] - bbox[5])
  718. if z == 0:
  719. z = 1.0
  720. return area*z
  721. def get_area(self):
  722. """Compute the area of the extent, extent in z direction is ignored"""
  723. if self.get_projection() == "LL":
  724. core.error(_("Area computation is not supported for LL projections"))
  725. bbox = self.get_spatial_extent()
  726. y = abs(bbox[0] - bbox[1])
  727. x = abs(bbox[2] - bbox[3])
  728. return x*y
  729. def get_spatial_extent(self):
  730. """Return a tuple (north, south, east, west, top, bottom) of the spatial extent"""
  731. return (self.get_north(), self.get_south, self.get_east(), self.get_west(), \
  732. self.get_top(), self.get_bottom())
  733. def get_spatial_extent_2d(self):
  734. """Return a tuple (north, south, east, west,) of the 2d spatial extent"""
  735. return (self.get_north(), self.get_south, self.get_east(), self.get_west())
  736. def get_north(self):
  737. """Get the northern edge of the map
  738. @return None if not found"""
  739. if self.D.has_key("north"):
  740. return self.D["north"]
  741. else:
  742. return None
  743. def get_south(self):
  744. """Get the southern edge of the map
  745. @return None if not found"""
  746. if self.D.has_key("south"):
  747. return self.D["south"]
  748. else:
  749. return None
  750. def get_east(self):
  751. """Get the eastern edge of the map
  752. @return None if not found"""
  753. if self.D.has_key("east"):
  754. return self.D["east"]
  755. else:
  756. return None
  757. def get_west(self):
  758. """Get the western edge of the map
  759. @return None if not found"""
  760. if self.D.has_key("west"):
  761. return self.D["west"]
  762. else:
  763. return None
  764. def get_top(self):
  765. """Get the top edge of the map
  766. @return None if not found"""
  767. if self.D.has_key("top"):
  768. return self.D["top"]
  769. else:
  770. return None
  771. def get_bottom(self):
  772. """Get the bottom edge of the map
  773. @return None if not found"""
  774. if self.D.has_key("bottom"):
  775. return self.D["bottom"]
  776. else:
  777. return None
  778. def print_info(self):
  779. """Print information about this class in human readable style"""
  780. # 0123456789012345678901234567890
  781. print " +-------------------- Spatial extent ----------------------------------------+"
  782. print " | North:...................... " + str(self.get_north())
  783. print " | South:...................... " + str(self.get_south())
  784. print " | East:.. .................... " + str(self.get_east())
  785. print " | West:....................... " + str(self.get_west())
  786. print " | Top:........................ " + str(self.get_top())
  787. print " | Bottom:..................... " + str(self.get_bottom())
  788. def print_shell_info(self):
  789. """Print information about this class in shell style"""
  790. print "north=" + str(self.get_north())
  791. print "south=" + str(self.get_south())
  792. print "east=" + str(self.get_east())
  793. print "west=" + str(self.get_west())
  794. print "top=" + str(self.get_top())
  795. print "bottom=" + str(self.get_bottom())
  796. ###############################################################################
  797. class raster_spatial_extent(spatial_extent):
  798. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  799. spatial_extent.__init__(self, "raster_spatial_extent", ident, north, south, east, west, top, bottom)
  800. class raster3d_spatial_extent(spatial_extent):
  801. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  802. spatial_extent.__init__(self, "raster3d_spatial_extent", ident, north, south, east, west, top, bottom)
  803. class vector_spatial_extent(spatial_extent):
  804. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  805. spatial_extent.__init__(self, "vector_spatial_extent", ident, north, south, east, west, top, bottom)
  806. class strds_spatial_extent(spatial_extent):
  807. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  808. spatial_extent.__init__(self, "strds_spatial_extent", ident, north, south, east, west, top, bottom)
  809. class str3ds_spatial_extent(spatial_extent):
  810. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  811. spatial_extent.__init__(self, "str3ds_spatial_extent", ident, north, south, east, west, top, bottom)
  812. class stvds_spatial_extent(spatial_extent):
  813. def __init__(self, ident=None, north=None, south=None, east=None, west=None, top=None, bottom=None):
  814. spatial_extent.__init__(self, "stvds_spatial_extent", ident, north, south, east, west, top, bottom)