spatial_extent.py 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  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.RasterSpatialExtent(
  8. ... ident="raster@PERMANENT", north=90, south=90, east=180, west=180,
  9. ... top=100, bottom=-20)
  10. >>> extent = tgis.Raster3DSpatialExtent(
  11. ... ident="raster3d@PERMANENT", north=90, south=90, east=180, west=180,
  12. ... top=100, bottom=-20)
  13. >>> extent = tgis.VectorSpatialExtent(
  14. ... ident="vector@PERMANENT", north=90, south=90, east=180, west=180,
  15. ... top=100, bottom=-20)
  16. >>> extent = tgis.STRDSSpatialExtent(
  17. ... ident="strds@PERMANENT", north=90, south=90, east=180, west=180,
  18. ... top=100, bottom=-20)
  19. >>> extent = tgis.STR3DSSpatialExtent(
  20. ... ident="str3ds@PERMANENT", north=90, south=90, east=180, west=180,
  21. ... top=100, bottom=-20)
  22. >>> extent = tgis.STVDSSpatialExtent(
  23. ... ident="stvds@PERMANENT", north=90, south=90, east=180, west=180,
  24. ... top=100, bottom=-20)
  25. @endcode
  26. (C) 2008-2011 by the GRASS Development Team
  27. This program is free software under the GNU General Public
  28. License (>=v2). Read the file COPYING that comes with GRASS
  29. for details.
  30. @author Soeren Gebbert
  31. """
  32. from base import *
  33. class SpatialExtent(SQLDatabaseInterface):
  34. """!This is the spatial extent base class for all maps and space time datasets
  35. This class implements a three dimensional axis aligned bounding box
  36. and functions to compute topological relationships
  37. Usage:
  38. @code
  39. >>> extent = SpatialExtent(table="raster_spatial_extent",
  40. ... ident="soil@PERMANENT", north=90, south=90, east=180, west=180,
  41. ... top=100, bottom=-20)
  42. >>> extent.id
  43. 'soil@PERMANENT'
  44. >>> extent.north
  45. 90.0
  46. >>> extent.south
  47. 90.0
  48. >>> extent.east
  49. 180.0
  50. >>> extent.west
  51. 180.0
  52. >>> extent.top
  53. 100.0
  54. >>> extent.bottom
  55. -20.0
  56. >>> extent.print_info()
  57. +-------------------- Spatial extent ----------------------------------------+
  58. | North:...................... 90.0
  59. | South:...................... 90.0
  60. | East:.. .................... 180.0
  61. | West:....................... 180.0
  62. | Top:........................ 100.0
  63. | Bottom:..................... -20.0
  64. >>> extent.print_shell_info()
  65. north=90.0
  66. south=90.0
  67. east=180.0
  68. west=180.0
  69. top=100.0
  70. bottom=-20.0
  71. @endcode
  72. """
  73. def __init__(self, table=None, ident=None, north=None, south=None,
  74. east=None, west=None, top=None, bottom=None, proj="XY"):
  75. SQLDatabaseInterface.__init__(self, table, ident)
  76. self.set_id(ident)
  77. self.set_spatial_extent(north, south, east, west, top, bottom)
  78. self.set_projection(proj)
  79. def overlapping_2d(self, extent):
  80. """!Return True if this (A) and the provided spatial extent (B) overlaps
  81. in two dimensional space.
  82. Code is lend from wind_overlap.c in lib/gis
  83. Overlapping includes the spatial relations:
  84. - contain
  85. - in
  86. - cover
  87. - covered
  88. - equivalent
  89. @code
  90. >>> A = SpatialExtent(north=80, south=20, east=60, west=10)
  91. >>> B = SpatialExtent(north=80, south=20, east=60, west=10)
  92. >>> A.overlapping_2d(B)
  93. True
  94. @endcode
  95. @param extent: The spatial extent to check overlapping with
  96. @return True or False
  97. """
  98. if self.get_projection() != extent.get_projection():
  99. core.error(_("Projections are different. Unable to compute "
  100. "overlapping_2d for spatial extents"))
  101. return False
  102. N = extent.get_north()
  103. S = extent.get_south()
  104. E = extent.get_east()
  105. W = extent.get_west()
  106. # Adjust the east and west in case of LL projection
  107. if self.get_projection() == "LL":
  108. while E < self.get_west():
  109. E += 360.0
  110. W += 360.0
  111. while W > self.get_east():
  112. E -= 360.0
  113. W -= 360.0
  114. if(self.get_north() <= S):
  115. return False
  116. if(self.get_south() >= N):
  117. return False
  118. if self.get_east() <= W:
  119. return False
  120. if self.get_west() >= E:
  121. return False
  122. return True
  123. def overlapping(self, extent):
  124. """!Return True if this (A) and the provided spatial
  125. extent (B) overlaps in three dimensional space.
  126. Overlapping includes the spatial relations:
  127. - contain
  128. - in
  129. - cover
  130. - covered
  131. - equivalent
  132. Usage:
  133. @code
  134. >>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
  135. >>> B = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
  136. >>> A.overlapping(B)
  137. True
  138. @endcode
  139. @param extent: The spatial extent to check overlapping with
  140. @return True or False
  141. """
  142. if not self.overlapping_2d(extent):
  143. return False
  144. T = extent.get_top()
  145. B = extent.get_bottom()
  146. if self.get_top() <= B:
  147. return False
  148. if self.get_bottom() >= T:
  149. return False
  150. return True
  151. def intersect_2d(self, extent):
  152. """!Return the two dimensional intersection as spatial_extent
  153. object or None in case no intersection was found.
  154. @param extent: The spatial extent to intersect with
  155. @return The intersection spatial extent
  156. """
  157. if not self.overlapping_2d(extent):
  158. return None
  159. eN = extent.get_north()
  160. eS = extent.get_south()
  161. eE = extent.get_east()
  162. eW = extent.get_west()
  163. N = self.get_north()
  164. S = self.get_south()
  165. E = self.get_east()
  166. W = self.get_west()
  167. # Adjust the east and west in case of LL projection
  168. if self.get_projection() == "LL":
  169. while eE < W:
  170. eE += 360.0
  171. eW += 360.0
  172. while eW > E:
  173. eE -= 360.0
  174. eW -= 360.0
  175. # Compute the extent
  176. nN = N
  177. nS = S
  178. nE = E
  179. nW = W
  180. if W < eW:
  181. nW = eW
  182. if E > eE:
  183. nE = eE
  184. if N > eN:
  185. nN = eN
  186. if S < eS:
  187. nS = eS
  188. new = SpatialExtent(north=nN, south=nS, east=nE, west=nW,
  189. top=0, bottom=0, proj=self.get_projection())
  190. return new
  191. def intersect(self, extent):
  192. """!Return the three dimensional intersection as spatial_extent
  193. object or None in case no intersection was found.
  194. Usage:
  195. @code
  196. >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
  197. ... bottom=-50, top=50)
  198. >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
  199. ... bottom=-50, top=50)
  200. >>> C = A.intersect(B)
  201. >>> C.print_info()
  202. +-------------------- Spatial extent ----------------------------------------+
  203. | North:...................... 80.0
  204. | South:...................... 20.0
  205. | East:.. .................... 60.0
  206. | West:....................... 10.0
  207. | Top:........................ 50.0
  208. | Bottom:..................... -50.0
  209. >>> B = SpatialExtent(north=40, south=30, east=60, west=10,
  210. ... bottom=-50, top=50)
  211. >>> C = A.intersect(B)
  212. >>> C.print_info()
  213. +-------------------- Spatial extent ----------------------------------------+
  214. | North:...................... 40.0
  215. | South:...................... 30.0
  216. | East:.. .................... 60.0
  217. | West:....................... 10.0
  218. | Top:........................ 50.0
  219. | Bottom:..................... -50.0
  220. >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
  221. ... bottom=-50, top=50)
  222. >>> C = A.intersect(B)
  223. >>> C.print_info()
  224. +-------------------- Spatial extent ----------------------------------------+
  225. | North:...................... 40.0
  226. | South:...................... 30.0
  227. | East:.. .................... 60.0
  228. | West:....................... 30.0
  229. | Top:........................ 50.0
  230. | Bottom:..................... -50.0
  231. >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
  232. ... bottom=-30, top=50)
  233. >>> C = A.intersect(B)
  234. >>> C.print_info()
  235. +-------------------- Spatial extent ----------------------------------------+
  236. | North:...................... 40.0
  237. | South:...................... 30.0
  238. | East:.. .................... 60.0
  239. | West:....................... 30.0
  240. | Top:........................ 50.0
  241. | Bottom:..................... -30.0
  242. >>> B = SpatialExtent(north=40, south=30, east=60, west=30,
  243. ... bottom=-30, top=30)
  244. >>> C = A.intersect(B)
  245. >>> C.print_info()
  246. +-------------------- Spatial extent ----------------------------------------+
  247. | North:...................... 40.0
  248. | South:...................... 30.0
  249. | East:.. .................... 60.0
  250. | West:....................... 30.0
  251. | Top:........................ 30.0
  252. | Bottom:..................... -30.0
  253. @endcode
  254. @param extent: The spatial extent to intersect with
  255. @return The intersection spatial extent
  256. """
  257. if not self.overlapping(extent):
  258. return None
  259. new = self.intersect_2d(extent)
  260. eT = extent.get_top()
  261. eB = extent.get_bottom()
  262. T = self.get_top()
  263. B = self.get_bottom()
  264. nT = T
  265. nB = B
  266. if B < eB:
  267. nB = eB
  268. if T > eT:
  269. nT = eT
  270. new.set_top(nT)
  271. new.set_bottom(nB)
  272. return new
  273. def is_in_2d(self, extent):
  274. """!Return True if this extent (A) is located in the provided spatial
  275. extent (B) in two dimensions.
  276. @verbatim
  277. _____
  278. |A _ |
  279. | |_| |
  280. |_____|B
  281. @endverbatim
  282. @param extent: The spatial extent
  283. @return True or False
  284. """
  285. if self.get_projection() != extent.get_projection():
  286. core.error(_("Projections are different. Unable to compute "
  287. "is_in_2d for spatial extents"))
  288. return False
  289. eN = extent.get_north()
  290. eS = extent.get_south()
  291. eE = extent.get_east()
  292. eW = extent.get_west()
  293. N = self.get_north()
  294. S = self.get_south()
  295. E = self.get_east()
  296. W = self.get_west()
  297. # Adjust the east and west in case of LL projection
  298. if self.get_projection() == "LL":
  299. while eE < W:
  300. eE += 360.0
  301. eW += 360.0
  302. while eW > E:
  303. eE -= 360.0
  304. eW -= 360.0
  305. if W <= eW:
  306. return False
  307. if E >= eE:
  308. return False
  309. if N >= eN:
  310. return False
  311. if S <= eS:
  312. return False
  313. return True
  314. def is_in(self, extent):
  315. """!Return True if this extent (A) is located in the provided spatial
  316. extent (B) in three dimensions.
  317. Usage:
  318. @code
  319. >>> A = SpatialExtent(north=79, south=21, east=59, west=11,
  320. ... bottom=-49, top=49)
  321. >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
  322. ... bottom=-50, top=50)
  323. >>> A.is_in(B)
  324. True
  325. >>> B.is_in(A)
  326. False
  327. @endcode
  328. @param extent: The spatial extent
  329. @return True or False
  330. """
  331. if not self.is_in_2d(extent):
  332. return False
  333. eT = extent.get_top()
  334. eB = extent.get_bottom()
  335. T = self.get_top()
  336. B = self.get_bottom()
  337. if B <= eB:
  338. return False
  339. if T >= eT:
  340. return False
  341. return True
  342. def contain_2d(self, extent):
  343. """!Return True if this extent (A) contains the provided spatial
  344. extent (B) in two dimensions.
  345. Usage:
  346. @code
  347. >>> A = SpatialExtent(north=80, south=20, east=60, west=10)
  348. >>> B = SpatialExtent(north=79, south=21, east=59, west=11)
  349. >>> A.contain_2d(B)
  350. True
  351. >>> B.contain_2d(A)
  352. False
  353. @endcode
  354. @param extent: The spatial extent
  355. @return True or False
  356. """
  357. return extent.is_in_2d(self)
  358. def contain(self, extent):
  359. """!Return True if this extent (A) contains the provided spatial
  360. extent (B) in three dimensions.
  361. Usage:
  362. @code
  363. >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
  364. ... bottom=-50, top=50)
  365. >>> B = SpatialExtent(north=79, south=21, east=59, west=11,
  366. ... bottom=-49, top=49)
  367. >>> A.contain(B)
  368. True
  369. >>> B.contain(A)
  370. False
  371. @endcode
  372. @param extent: The spatial extent
  373. @return True or False
  374. """
  375. return extent.is_in(self)
  376. def equivalent_2d(self, extent):
  377. """!Return True if this extent (A) is equal to the provided spatial
  378. extent (B) in two dimensions.
  379. Usage:
  380. @code
  381. >>> A = SpatialExtent(north=80, south=20, east=60, west=10)
  382. >>> B = SpatialExtent(north=80, south=20, east=60, west=10)
  383. >>> A.equivalent_2d(B)
  384. True
  385. >>> B.equivalent_2d(A)
  386. True
  387. @endcode
  388. @param extent: The spatial extent
  389. @return True or False
  390. """
  391. if self.get_projection() != extent.get_projection():
  392. core.error(_("Projections are different. Unable to compute "
  393. "equivalent_2d for spatial extents"))
  394. return False
  395. eN = extent.get_north()
  396. eS = extent.get_south()
  397. eE = extent.get_east()
  398. eW = extent.get_west()
  399. N = self.get_north()
  400. S = self.get_south()
  401. E = self.get_east()
  402. W = self.get_west()
  403. # Adjust the east and west in case of LL projection
  404. if self.get_projection() == "LL":
  405. while eE < W:
  406. eE += 360.0
  407. eW += 360.0
  408. while eW > E:
  409. eE -= 360.0
  410. eW -= 360.0
  411. if W != eW:
  412. return False
  413. if E != eE:
  414. return False
  415. if N != eN:
  416. return False
  417. if S != eS:
  418. return False
  419. return True
  420. def equivalent(self, extent):
  421. """!Return True if this extent (A) is equal to the provided spatial
  422. extent (B) in three dimensions.
  423. Usage:
  424. @code
  425. >>> A = SpatialExtent(north=80, south=20, east=60, west=10,
  426. ... bottom=-50, top=50)
  427. >>> B = SpatialExtent(north=80, south=20, east=60, west=10,
  428. ... bottom=-50, top=50)
  429. >>> A.equivalent(B)
  430. True
  431. >>> B.equivalent(A)
  432. True
  433. @endcode
  434. @param extent: The spatial extent
  435. @return True or False
  436. """
  437. if not self.equivalent_2d(extent):
  438. return False
  439. eT = extent.get_top()
  440. eB = extent.get_bottom()
  441. T = self.get_top()
  442. B = self.get_bottom()
  443. if B != eB:
  444. return False
  445. if T != eT:
  446. return False
  447. return True
  448. def cover_2d(self, extent):
  449. """!Return True if this extent (A) covers the provided spatial
  450. extent (B) in two dimensions.
  451. @verbatim
  452. _____ _____ _____ _____
  453. |A __| |__ A| |A | B| |B | A|
  454. | |B | | B| | | |__| |__| |
  455. |__|__| |__|__| |_____| |_____|
  456. _____ _____ _____ _____
  457. |A|B| | |A __| |A _ | |__ A|
  458. | |_| | | |__|B | |B| | B|__| |
  459. |_____| |_____| |_|_|_| |_____|
  460. _____ _____ _____ _____
  461. |A|B | |_____|A |A|B|A| |_____|A
  462. | | | |B | | | | | |_____|B
  463. |_|___| |_____| |_|_|_| |_____|A
  464. @endverbatim
  465. The following cases are excluded:
  466. - contain
  467. - in
  468. - equivalent
  469. @param extent: The spatial extent
  470. @return True or False
  471. """
  472. if self.get_projection() != extent.get_projection():
  473. core.error(_("Projections are different. Unable to compute cover_2d for spatial extents"))
  474. return False
  475. # Exclude equivalent_2d
  476. if self.equivalent_2d(extent):
  477. return False
  478. eN = extent.get_north()
  479. eS = extent.get_south()
  480. eE = extent.get_east()
  481. eW = extent.get_west()
  482. N = self.get_north()
  483. S = self.get_south()
  484. E = self.get_east()
  485. W = self.get_west()
  486. # Adjust the east and west in case of LL projection
  487. if self.get_projection() == "LL":
  488. while eE < W:
  489. eE += 360.0
  490. eW += 360.0
  491. while eW > E:
  492. eE -= 360.0
  493. eW -= 360.0
  494. # Edges of extent located outside of self are not allowed
  495. if E < eW:
  496. return False
  497. if W > eE:
  498. return False
  499. if N < eS:
  500. return False
  501. if S > eN:
  502. return False
  503. # First we check that at least one edge of extent meets an edge of self
  504. if W != eW and E != eE and N != eN and S != eS:
  505. return False
  506. # We check that at least one edge of extent is located in self
  507. edge_count = 0
  508. if W < eW and E > eW:
  509. edge_count += 1
  510. if E > eE and W < eE:
  511. edge_count += 1
  512. if N > eN and S < eN:
  513. edge_count += 1
  514. if S < eS and N > eS:
  515. edge_count += 1
  516. if edge_count == 0:
  517. return False
  518. return True
  519. def cover(self, extent):
  520. """!Return True if this extent covers the provided spatial
  521. extent in three dimensions.
  522. The following cases are excluded:
  523. - contain
  524. - in
  525. - equivalent
  526. @param extent: The spatial extent
  527. @return True or False
  528. """
  529. if self.get_projection() != extent.get_projection():
  530. core.error(_("Projections are different. Unable to compute "
  531. "cover for spatial extents"))
  532. return False
  533. # Exclude equivalent_2d
  534. if self.equivalent_2d(extent):
  535. return False
  536. eN = extent.get_north()
  537. eS = extent.get_south()
  538. eE = extent.get_east()
  539. eW = extent.get_west()
  540. eT = extent.get_top()
  541. eB = extent.get_bottom()
  542. N = self.get_north()
  543. S = self.get_south()
  544. E = self.get_east()
  545. W = self.get_west()
  546. T = self.get_top()
  547. B = self.get_bottom()
  548. # Adjust the east and west in case of LL projection
  549. if self.get_projection() == "LL":
  550. while eE < W:
  551. eE += 360.0
  552. eW += 360.0
  553. while eW > E:
  554. eE -= 360.0
  555. eW -= 360.0
  556. # Edges of extent located outside of self are not allowed
  557. if E <= eW:
  558. return False
  559. if W >= eE:
  560. return False
  561. if N <= eS:
  562. return False
  563. if S >= eN:
  564. return False
  565. if T <= eB:
  566. return False
  567. if B >= eT:
  568. return False
  569. # First we check that at least one edge of extent meets an edge of self
  570. if W != eW and E != eE and N != eN and S != eS and B != eB and T != eT:
  571. return False
  572. # We check that at least one edge of extent is located in self
  573. edge_count = 0
  574. if W < eW and E > eW:
  575. edge_count += 1
  576. if E > eE and W < eE:
  577. edge_count += 1
  578. if N > eN and S < eN:
  579. edge_count += 1
  580. if S < eS and N > eS:
  581. edge_count += 1
  582. if N > eN and S < eN:
  583. edge_count += 1
  584. if S < eS and N > eS:
  585. edge_count += 1
  586. if T > eT and B < eT:
  587. edge_count += 1
  588. if B < eB and T > eB:
  589. edge_count += 1
  590. if edge_count == 0:
  591. return False
  592. return True
  593. def covered_2d(self, extent):
  594. """!Return True if this extent is covered by the provided spatial
  595. extent in two dimensions.
  596. The following cases are excluded:
  597. - contain
  598. - in
  599. - equivalent
  600. @param extent: The spatial extent
  601. @return True or False
  602. """
  603. return extent.cover_2d(self)
  604. def covered(self, extent):
  605. """!Return True if this extent is covered by the provided spatial
  606. extent in three dimensions.
  607. The following cases are excluded:
  608. - contain
  609. - in
  610. - equivalent
  611. @param extent: The spatial extent
  612. @return True or False
  613. """
  614. return extent.cover(self)
  615. def overlap_2d(self, extent):
  616. """!Return True if this extent (A) overlaps with the provided spatial
  617. extent (B) in two dimensions.
  618. Code is lend from wind_overlap.c in lib/gis
  619. @verbatim
  620. _____
  621. |A __|__
  622. | | | B|
  623. |__|__| |
  624. |_____|
  625. @endverbatim
  626. The following cases are excluded:
  627. - contain
  628. - in
  629. - cover
  630. - covered
  631. - equivalent
  632. @param extent: The spatial extent
  633. @return True or False
  634. """
  635. if self.contain_2d(extent):
  636. return False
  637. if self.is_in_2d(extent):
  638. return False
  639. if self.cover_2d(extent):
  640. return False
  641. if self.covered_2d(extent):
  642. return False
  643. if self.equivalent_2d(extent):
  644. return False
  645. N = extent.get_north()
  646. S = extent.get_south()
  647. E = extent.get_east()
  648. W = extent.get_west()
  649. # Adjust the east and west in case of LL projection
  650. if self.get_projection() == "LL":
  651. while E < self.get_west():
  652. E += 360.0
  653. W += 360.0
  654. while W > self.get_east():
  655. E -= 360.0
  656. W -= 360.0
  657. if(self.get_north() <= S):
  658. return False
  659. if(self.get_south() >= N):
  660. return False
  661. if self.get_east() <= W:
  662. return False
  663. if self.get_west() >= E:
  664. return False
  665. return True
  666. def overlap(self, extent):
  667. """!Return True if this extent overlaps with the provided spatial
  668. extent in three dimensions.
  669. The following cases are excluded:
  670. - contain
  671. - in
  672. - cover
  673. - covered
  674. - equivalent
  675. @param extent: The spatial extent
  676. @return True or False
  677. """
  678. if self.is_in(extent):
  679. return False
  680. if self.contain(extent):
  681. return False
  682. if self.cover(extent):
  683. return False
  684. if self.covered(extent):
  685. return False
  686. if self.equivalent(extent):
  687. return False
  688. N = extent.get_north()
  689. S = extent.get_south()
  690. E = extent.get_east()
  691. W = extent.get_west()
  692. T = extent.get_top()
  693. B = extent.get_bottom()
  694. # Adjust the east and west in case of LL projection
  695. if self.get_projection() == "LL":
  696. while E < self.get_west():
  697. E += 360.0
  698. W += 360.0
  699. while W > self.get_east():
  700. E -= 360.0
  701. W -= 360.0
  702. if(self.get_north() <= S):
  703. return False
  704. if(self.get_south() >= N):
  705. return False
  706. if self.get_east() <= W:
  707. return False
  708. if self.get_west() >= E:
  709. return False
  710. if self.get_top() <= B:
  711. return False
  712. if self.get_bottom() >= T:
  713. return False
  714. return True
  715. def meet_2d(self, extent):
  716. """!Return True if this extent (A) meets with the provided spatial
  717. extent (B) in two dimensions.
  718. @verbatim
  719. _____ _____
  720. | A | B |
  721. |_____| |
  722. |_____|
  723. _____ _____
  724. | B | A |
  725. | | |
  726. |_____|_____|
  727. ___
  728. | A |
  729. | |
  730. |___|
  731. | B |
  732. | |
  733. |_____|
  734. _____
  735. | B |
  736. | |
  737. |_____|_
  738. | A |
  739. | |
  740. |_____|
  741. @endverbatim
  742. @param extent: The spatial extent
  743. @return True or False
  744. """
  745. eN = extent.get_north()
  746. eS = extent.get_south()
  747. eE = extent.get_east()
  748. eW = extent.get_west()
  749. eT = extent.get_top()
  750. eB = extent.get_bottom()
  751. N = self.get_north()
  752. S = self.get_south()
  753. E = self.get_east()
  754. W = self.get_west()
  755. # Adjust the east and west in case of LL projection
  756. if self.get_projection() == "LL":
  757. while eE < W:
  758. eE += 360.0
  759. eW += 360.0
  760. while eW > E:
  761. eE -= 360.0
  762. eW -= 360.0
  763. edge = None
  764. edge_count = 0
  765. if E == eW:
  766. edge = "E"
  767. edge_count += 1
  768. if W == eE:
  769. edge = "W"
  770. edge_count += 1
  771. if N == eS:
  772. edge = "N"
  773. edge_count += 1
  774. if S == eN:
  775. edge = "S"
  776. edge_count += 1
  777. # Meet a a single edge only
  778. if edge_count != 1:
  779. return False
  780. # Check boundaries of the faces
  781. if edge == "E" or edge == "W":
  782. if N < eS or S > eN:
  783. return False
  784. if edge == "N" or edge == "S":
  785. if E < eW or W > eE:
  786. return False
  787. return True
  788. def meet(self, extent):
  789. """!Return True if this extent meets with the provided spatial
  790. extent in three dimensions.
  791. @param extent: The spatial extent
  792. @return True or False
  793. """
  794. eN = extent.get_north()
  795. eS = extent.get_south()
  796. eE = extent.get_east()
  797. eW = extent.get_west()
  798. eT = extent.get_top()
  799. eB = extent.get_bottom()
  800. N = self.get_north()
  801. S = self.get_south()
  802. E = self.get_east()
  803. W = self.get_west()
  804. T = self.get_top()
  805. B = self.get_bottom()
  806. # Adjust the east and west in case of LL projection
  807. if self.get_projection() == "LL":
  808. while eE < W:
  809. eE += 360.0
  810. eW += 360.0
  811. while eW > E:
  812. eE -= 360.0
  813. eW -= 360.0
  814. edge = None
  815. edge_count = 0
  816. if E == eW:
  817. edge = "E"
  818. edge_count += 1
  819. if W == eE:
  820. edge = "W"
  821. edge_count += 1
  822. if N == eS:
  823. edge = "N"
  824. edge_count += 1
  825. if S == eN:
  826. edge = "S"
  827. edge_count += 1
  828. if T == eB:
  829. edge = "T"
  830. edge_count += 1
  831. if B == eT:
  832. edge = "B"
  833. edge_count += 1
  834. # Meet a single edge only
  835. if edge_count != 1:
  836. return False
  837. # Check boundaries of the faces
  838. if edge == "E" or edge == "W":
  839. if N < eS or S > eN:
  840. return False
  841. if T < eB or B > eT:
  842. return False
  843. if edge == "N" or edge == "S":
  844. if E < eW or W > eE:
  845. return False
  846. if T < eB or B > eT:
  847. return False
  848. if edge == "T" or edge == "B":
  849. if E < eW or W > eE:
  850. return False
  851. if N < eS or S > eN:
  852. return False
  853. return True
  854. def disjoint_2d(self, extent):
  855. """!Return True if this extent (A) is disjoint with the provided spatial
  856. extent (B) in three dimensions.
  857. @verbatim
  858. _____
  859. | A |
  860. |_____|
  861. _______
  862. | B |
  863. |_______|
  864. @endverbatim
  865. @param extent: The spatial extent
  866. @return True or False
  867. """
  868. if self.overlapping_2d(extent) or self.meet_2d(extent):
  869. return False
  870. return True
  871. def disjoint(self, extent):
  872. """!Return True if this extent is disjoint with the provided spatial
  873. extent in three dimensions.
  874. @param extent: The spatial extent
  875. @return True or False
  876. """
  877. if self.overlapping(extent) or self.meet(extent):
  878. return False
  879. return True
  880. def spatial_relation_2d(self, extent):
  881. """!Returns the two dimensional spatial relation between this
  882. extent and the provided spatial extent in two dimensions.
  883. Spatial relations are:
  884. - disjoint
  885. - meet
  886. - overlap
  887. - cover
  888. - covered
  889. - in
  890. - contain
  891. - equivalent
  892. Usage: see self.spatial_relation()
  893. """
  894. if self.equivalent_2d(extent):
  895. return "equivalent"
  896. if self.contain_2d(extent):
  897. return "contain"
  898. if self.is_in_2d(extent):
  899. return "in"
  900. if self.cover_2d(extent):
  901. return "cover"
  902. if self.covered_2d(extent):
  903. return "covered"
  904. if self.overlap_2d(extent):
  905. return "overlap"
  906. if self.meet_2d(extent):
  907. return "meet"
  908. if self.disjoint_2d(extent):
  909. return "disjoint"
  910. return "unknown"
  911. def spatial_relation(self, extent):
  912. """!Returns the two dimensional spatial relation between this
  913. extent and the provided spatial extent in three dimensions.
  914. Spatial relations are:
  915. - disjoint
  916. - meet
  917. - overlap
  918. - cover
  919. - covered
  920. - in
  921. - contain
  922. - equivalent
  923. Usage:
  924. @code
  925. >>> A = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
  926. >>> B = SpatialExtent(north=80, south=20, east=60, west=10, bottom=-50, top=50)
  927. >>> A.spatial_relation(B)
  928. 'equivalent'
  929. >>> B.spatial_relation(A)
  930. 'equivalent'
  931. >>> B = SpatialExtent(north=70, south=20, east=60, west=10, bottom=-50, top=50)
  932. >>> A.spatial_relation_2d(B)
  933. 'cover'
  934. >>> A.spatial_relation(B)
  935. 'cover'
  936. >>> B = SpatialExtent(north=70, south=30, east=60, west=10, bottom=-50, top=50)
  937. >>> A.spatial_relation_2d(B)
  938. 'cover'
  939. >>> A.spatial_relation(B)
  940. 'cover'
  941. >>> B.spatial_relation_2d(A)
  942. 'covered'
  943. >>> B.spatial_relation(A)
  944. 'covered'
  945. >>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=-50, top=50)
  946. >>> A.spatial_relation_2d(B)
  947. 'cover'
  948. >>> B.spatial_relation_2d(A)
  949. 'covered'
  950. >>> A.spatial_relation(B)
  951. 'cover'
  952. >>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-50, top=50)
  953. >>> B.spatial_relation(A)
  954. 'covered'
  955. >>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-50, top=50)
  956. >>> A.spatial_relation_2d(B)
  957. 'contain'
  958. >>> A.spatial_relation(B)
  959. 'cover'
  960. >>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-40, top=50)
  961. >>> A.spatial_relation(B)
  962. 'cover'
  963. >>> B = SpatialExtent(north=70, south=30, east=50, west=20, bottom=-40, top=40)
  964. >>> A.spatial_relation(B)
  965. 'contain'
  966. >>> B.spatial_relation(A)
  967. 'in'
  968. >>> B = SpatialExtent(north=90, south=30, east=50, west=20, bottom=-40, top=40)
  969. >>> A.spatial_relation_2d(B)
  970. 'overlap'
  971. >>> A.spatial_relation(B)
  972. 'overlap'
  973. >>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-40, top=40)
  974. >>> A.spatial_relation_2d(B)
  975. 'in'
  976. >>> A.spatial_relation(B)
  977. 'overlap'
  978. >>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-40, top=60)
  979. >>> A.spatial_relation(B)
  980. 'overlap'
  981. >>> B = SpatialExtent(north=90, south=5, east=70, west=5, bottom=-60, top=60)
  982. >>> A.spatial_relation(B)
  983. 'in'
  984. >>> A = SpatialExtent(north=80, south=60, east=60, west=10, bottom=-50, top=50)
  985. >>> B = SpatialExtent(north=60, south=20, east=60, west=10, bottom=-50, top=50)
  986. >>> A.spatial_relation_2d(B)
  987. 'meet'
  988. >>> A.spatial_relation(B)
  989. 'meet'
  990. >>> A = SpatialExtent(north=60, south=40, east=60, west=10, bottom=-50, top=50)
  991. >>> B = SpatialExtent(north=80, south=60, east=60, west=10, bottom=-50, top=50)
  992. >>> A.spatial_relation_2d(B)
  993. 'meet'
  994. >>> A.spatial_relation(B)
  995. 'meet'
  996. >>> A = SpatialExtent(north=80, south=40, east=60, west=40, bottom=-50, top=50)
  997. >>> B = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  998. >>> A.spatial_relation_2d(B)
  999. 'meet'
  1000. >>> A.spatial_relation(B)
  1001. 'meet'
  1002. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1003. >>> B = SpatialExtent(north=90, south=30, east=60, west=40, bottom=-50, top=50)
  1004. >>> A.spatial_relation_2d(B)
  1005. 'meet'
  1006. >>> A.spatial_relation(B)
  1007. 'meet'
  1008. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1009. >>> B = SpatialExtent(north=70, south=50, east=60, west=40, bottom=-50, top=50)
  1010. >>> A.spatial_relation_2d(B)
  1011. 'meet'
  1012. >>> A.spatial_relation(B)
  1013. 'meet'
  1014. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1015. >>> B = SpatialExtent(north=60, south=20, east=60, west=40, bottom=-50, top=50)
  1016. >>> A.spatial_relation_2d(B)
  1017. 'meet'
  1018. >>> A.spatial_relation(B)
  1019. 'meet'
  1020. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1021. >>> B = SpatialExtent(north=40, south=20, east=60, west=40, bottom=-50, top=50)
  1022. >>> A.spatial_relation_2d(B)
  1023. 'disjoint'
  1024. >>> A.spatial_relation(B)
  1025. 'disjoint'
  1026. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1027. >>> B = SpatialExtent(north=60, south=20, east=60, west=40, bottom=-60, top=60)
  1028. >>> A.spatial_relation(B)
  1029. 'meet'
  1030. >>> A = SpatialExtent(north=80, south=40, east=40, west=20, bottom=-50, top=50)
  1031. >>> B = SpatialExtent(north=90, south=30, east=60, west=40, bottom=-40, top=40)
  1032. >>> A.spatial_relation(B)
  1033. 'meet'
  1034. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1035. >>> B = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1036. >>> A.spatial_relation(B)
  1037. 'meet'
  1038. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1039. >>> B = SpatialExtent(north=80, south=50, east=60, west=30, bottom=-50, top=0)
  1040. >>> A.spatial_relation(B)
  1041. 'meet'
  1042. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1043. >>> B = SpatialExtent(north=70, south=50, east=50, west=30, bottom=-50, top=0)
  1044. >>> A.spatial_relation(B)
  1045. 'meet'
  1046. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1047. >>> B = SpatialExtent(north=90, south=30, east=70, west=10, bottom=-50, top=0)
  1048. >>> A.spatial_relation(B)
  1049. 'meet'
  1050. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1051. >>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=-50, top=0)
  1052. >>> A.spatial_relation(B)
  1053. 'meet'
  1054. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1055. >>> B = SpatialExtent(north=80, south=40, east=60, west=20, bottom=0, top=50)
  1056. >>> A.spatial_relation(B)
  1057. 'meet'
  1058. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1059. >>> B = SpatialExtent(north=80, south=50, east=60, west=30, bottom=0, top=50)
  1060. >>> A.spatial_relation(B)
  1061. 'meet'
  1062. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1063. >>> B = SpatialExtent(north=70, south=50, east=50, west=30, bottom=0, top=50)
  1064. >>> A.spatial_relation(B)
  1065. 'meet'
  1066. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1067. >>> B = SpatialExtent(north=90, south=30, east=70, west=10, bottom=0, top=50)
  1068. >>> A.spatial_relation(B)
  1069. 'meet'
  1070. >>> A = SpatialExtent(north=80, south=40, east=60, west=20, bottom=-50, top=0)
  1071. >>> B = SpatialExtent(north=70, south=30, east=50, west=10, bottom=0, top=50)
  1072. >>> A.spatial_relation(B)
  1073. 'meet'
  1074. @endverbatim
  1075. """
  1076. if self.equivalent(extent):
  1077. return "equivalent"
  1078. if self.contain(extent):
  1079. return "contain"
  1080. if self.is_in(extent):
  1081. return "in"
  1082. if self.cover(extent):
  1083. return "cover"
  1084. if self.covered(extent):
  1085. return "covered"
  1086. if self.overlap(extent):
  1087. return "overlap"
  1088. if self.meet(extent):
  1089. return "meet"
  1090. if self.disjoint(extent):
  1091. return "disjoint"
  1092. return "unknown"
  1093. def set_spatial_extent(self, north, south, east, west, top, bottom):
  1094. """!Set the three dimensional spatial extent"""
  1095. self.set_north(north)
  1096. self.set_south(south)
  1097. self.set_east(east)
  1098. self.set_west(west)
  1099. self.set_top(top)
  1100. self.set_bottom(bottom)
  1101. def set_projection(self, proj):
  1102. """!Set the projection of the spatial extent it should be XY or LL.
  1103. As default the projection is XY
  1104. """
  1105. if proj is None or (proj != "XY" and proj != "LL"):
  1106. self.D["proj"] = "XY"
  1107. else:
  1108. self.D["proj"] = proj
  1109. def set_spatial_extent_2d(self, north, south, east, west):
  1110. """!Set the two dimensional spatial extent"""
  1111. self.set_north(north)
  1112. self.set_south(south)
  1113. self.set_east(east)
  1114. self.set_west(west)
  1115. def set_id(self, ident):
  1116. """!Convenient method to set the unique identifier (primary key)"""
  1117. self.ident = ident
  1118. self.D["id"] = ident
  1119. def set_north(self, north):
  1120. """!Set the northern edge of the map"""
  1121. if north is not None:
  1122. self.D["north"] = float(north)
  1123. else:
  1124. self.D["north"] = None
  1125. def set_south(self, south):
  1126. """!Set the southern edge of the map"""
  1127. if south is not None:
  1128. self.D["south"] = float(south)
  1129. else:
  1130. self.D["south"] = None
  1131. def set_west(self, west):
  1132. """!Set the western edge of the map"""
  1133. if west is not None:
  1134. self.D["west"] = float(west)
  1135. else:
  1136. self.D["west"] = None
  1137. def set_east(self, east):
  1138. """!Set the eastern edge of the map"""
  1139. if east is not None:
  1140. self.D["east"] = float(east)
  1141. else:
  1142. self.D["east"] = None
  1143. def set_top(self, top):
  1144. """!Set the top edge of the map"""
  1145. if top is not None:
  1146. self.D["top"] = float(top)
  1147. else:
  1148. self.D["top"] = None
  1149. def set_bottom(self, bottom):
  1150. """!Set the bottom edge of the map"""
  1151. if bottom is not None:
  1152. self.D["bottom"] = float(bottom)
  1153. else:
  1154. self.D["bottom"] = None
  1155. def get_id(self):
  1156. """!Convenient method to get the unique identifier (primary key)
  1157. @return None if not found
  1158. """
  1159. if "id" in self.D:
  1160. return self.D["id"]
  1161. else:
  1162. return None
  1163. def get_projection(self):
  1164. """!Get the projection of the spatial extent"""
  1165. return self.D["proj"]
  1166. def get_volume(self):
  1167. """!Compute the volume of the extent, in case z is zero
  1168. (top == bottom or top - bottom = 1) the area is returned"""
  1169. if self.get_projection() == "LL":
  1170. core.error(_("Volume computation is not supported "
  1171. "for LL projections"))
  1172. area = self.get_area()
  1173. bbox = self.get_spatial_extent()
  1174. z = abs(bbox[4] - bbox[5])
  1175. if z == 0:
  1176. z = 1.0
  1177. return area * z
  1178. def get_area(self):
  1179. """!Compute the area of the extent, extent in z direction is ignored"""
  1180. if self.get_projection() == "LL":
  1181. core.error(_("Area computation is not supported "
  1182. "for LL projections"))
  1183. bbox = self.get_spatial_extent()
  1184. y = abs(bbox[0] - bbox[1])
  1185. x = abs(bbox[2] - bbox[3])
  1186. return x * y
  1187. def get_spatial_extent(self):
  1188. """!Return a tuple (north, south, east, west, top, bottom)
  1189. of the spatial extent"""
  1190. return (
  1191. self.north, self.south, self.east, self.west,
  1192. self.top, self.bottom)
  1193. def get_spatial_extent_2d(self):
  1194. """!Return a tuple (north, south, east, west,) of the 2d spatial extent
  1195. """
  1196. return (self.north, self.south, self.east, self.west)
  1197. def get_north(self):
  1198. """!Get the northern edge of the map
  1199. @return None if not found"""
  1200. if "north" in self.D:
  1201. return self.D["north"]
  1202. else:
  1203. return None
  1204. def get_south(self):
  1205. """!Get the southern edge of the map
  1206. @return None if not found"""
  1207. if "south" in self.D:
  1208. return self.D["south"]
  1209. else:
  1210. return None
  1211. def get_east(self):
  1212. """!Get the eastern edge of the map
  1213. @return None if not found"""
  1214. if "east" in self.D:
  1215. return self.D["east"]
  1216. else:
  1217. return None
  1218. def get_west(self):
  1219. """!Get the western edge of the map
  1220. @return None if not found"""
  1221. if "west" in self.D:
  1222. return self.D["west"]
  1223. else:
  1224. return None
  1225. def get_top(self):
  1226. """!Get the top edge of the map
  1227. @return None if not found"""
  1228. if "top" in self.D:
  1229. return self.D["top"]
  1230. else:
  1231. return None
  1232. def get_bottom(self):
  1233. """!Get the bottom edge of the map
  1234. @return None if not found"""
  1235. if "bottom" in self.D:
  1236. return self.D["bottom"]
  1237. else:
  1238. return None
  1239. id = property(fget=get_id, fset=set_id)
  1240. north = property(fget=get_north, fset=set_north)
  1241. south = property(fget=get_south, fset=set_south)
  1242. east = property(fget=get_east, fset=set_east)
  1243. west = property(fget=get_west, fset=set_west)
  1244. top = property(fget=get_top, fset=set_top)
  1245. bottom= property(fget=get_bottom, fset=set_bottom)
  1246. def print_info(self):
  1247. """!Print information about this class in human readable style"""
  1248. # 0123456789012345678901234567890
  1249. print " +-------------------- Spatial extent ----------------------------------------+"
  1250. print " | North:...................... " + str(self.get_north())
  1251. print " | South:...................... " + str(self.get_south())
  1252. print " | East:.. .................... " + str(self.get_east())
  1253. print " | West:....................... " + str(self.get_west())
  1254. print " | Top:........................ " + str(self.get_top())
  1255. print " | Bottom:..................... " + str(self.get_bottom())
  1256. def print_shell_info(self):
  1257. """Print information about this class in shell style"""
  1258. print "north=" + str(self.get_north())
  1259. print "south=" + str(self.get_south())
  1260. print "east=" + str(self.get_east())
  1261. print "west=" + str(self.get_west())
  1262. print "top=" + str(self.get_top())
  1263. print "bottom=" + str(self.get_bottom())
  1264. ###############################################################################
  1265. class RasterSpatialExtent(SpatialExtent):
  1266. def __init__(self, ident=None, north=None, south=None, east=None,
  1267. west=None, top=None, bottom=None):
  1268. SpatialExtent.__init__(self, "raster_spatial_extent",
  1269. ident, north, south, east, west, top, bottom)
  1270. class Raster3DSpatialExtent(SpatialExtent):
  1271. def __init__(self, ident=None, north=None, south=None, east=None,
  1272. west=None, top=None, bottom=None):
  1273. SpatialExtent.__init__(self, "raster3d_spatial_extent",
  1274. ident, north, south, east, west, top, bottom)
  1275. class VectorSpatialExtent(SpatialExtent):
  1276. def __init__(self, ident=None, north=None, south=None, east=None,
  1277. west=None, top=None, bottom=None):
  1278. SpatialExtent.__init__(self, "vector_spatial_extent",
  1279. ident, north, south, east, west, top, bottom)
  1280. class STRDSSpatialExtent(SpatialExtent):
  1281. def __init__(self, ident=None, north=None, south=None, east=None,
  1282. west=None, top=None, bottom=None):
  1283. SpatialExtent.__init__(self, "strds_spatial_extent",
  1284. ident, north, south, east, west, top, bottom)
  1285. class STR3DSSpatialExtent(SpatialExtent):
  1286. def __init__(self, ident=None, north=None, south=None, east=None,
  1287. west=None, top=None, bottom=None):
  1288. SpatialExtent.__init__(self, "str3ds_spatial_extent",
  1289. ident, north, south, east, west, top, bottom)
  1290. class STVDSSpatialExtent(SpatialExtent):
  1291. def __init__(self, ident=None, north=None, south=None, east=None,
  1292. west=None, top=None, bottom=None):
  1293. SpatialExtent.__init__(self, "stvds_spatial_extent",
  1294. ident, north, south, east, west, top, bottom)
  1295. ###############################################################################
  1296. if __name__ == "__main__":
  1297. import doctest
  1298. doctest.testmod()