spatial_extent.py 46 KB

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