139 |
numshapes, shapetype, mins, maxs = self.shapefile.info() |
numshapes, shapetype, mins, maxs = self.shapefile.info() |
140 |
self.numshapes = numshapes |
self.numshapes = numshapes |
141 |
self.shapetype = shapelib_shapetypes[shapetype] |
self.shapetype = shapelib_shapetypes[shapetype] |
142 |
self.bbox = mins[:2] + maxs[:2] |
|
143 |
|
# if there are shapes, set the bbox accordinly. Otherwise |
144 |
|
# set it to None. |
145 |
|
if self.numshapes: |
146 |
|
self.bbox = mins[:2] + maxs[:2] |
147 |
|
else: |
148 |
|
self.bbox = None |
149 |
|
|
150 |
# estimate a good depth for the quad tree. Each depth |
# estimate a good depth for the quad tree. Each depth |
151 |
# multiplies the number of nodes by four, therefore we |
# multiplies the number of nodes by four, therefore we |
160 |
maxdepth) |
maxdepth) |
161 |
|
|
162 |
def BoundingBox(self): |
def BoundingBox(self): |
163 |
"""Return the bounding box of the layer's shapes in their default |
"""Return the layer's bounding box in the intrinsic coordinate system. |
164 |
coordinate system""" |
|
165 |
|
If the layer has no shapes, return None. |
166 |
|
""" |
167 |
|
# The bbox will be set by open_shapefile just as we need it |
168 |
|
# here. |
169 |
self.open_shapefile() |
self.open_shapefile() |
170 |
return self.bbox |
return self.bbox |
171 |
|
|
172 |
def LatLongBoundingBox(self): |
def LatLongBoundingBox(self): |
173 |
"""Return the layer's bounding box in lat/long coordinates""" |
"""Return the layer's bounding box in lat/long coordinates. |
174 |
llx, lly, urx, ury = self.BoundingBox() |
|
175 |
if self.projection is not None: |
Return None, if the layer doesn't contain any shapes. |
176 |
llx, lly = self.projection.Inverse(llx, lly) |
""" |
177 |
urx, ury = self.projection.Inverse(urx, ury) |
bbox = self.BoundingBox() |
178 |
return llx, lly, urx, ury |
if bbox is not None: |
179 |
|
llx, lly, urx, ury = bbox |
180 |
|
if self.projection is not None: |
181 |
|
llx, lly = self.projection.Inverse(llx, lly) |
182 |
|
urx, ury = self.projection.Inverse(urx, ury) |
183 |
|
return llx, lly, urx, ury |
184 |
|
else: |
185 |
|
return None |
186 |
|
|
187 |
def NumShapes(self): |
def NumShapes(self): |
188 |
"""Return the number of shapes in the layer""" |
"""Return the number of shapes in the layer""" |