本文整理汇总了Python中geojson.MultiPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python geojson.MultiPolygon方法的具体用法?Python geojson.MultiPolygon怎么用?Python geojson.MultiPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geojson
的用法示例。
在下文中一共展示了geojson.MultiPolygon方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_entity_add_country_shape
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import MultiPolygon [as 别名]
def test_entity_add_country_shape(air_quality_observed):
air_quality_observed.pop('location')
air_quality_observed['address']['value'] = {
"addressCountry": "MX",
}
r = geocoding.add_location(air_quality_observed)
assert r is air_quality_observed
assert 'location' in r
assert r['location']['type'] == 'geo:json'
geo = r['location']['value']
assert geo['type'] == 'MultiPolygon'
multi_polygon = geojson.MultiPolygon(geo['coordinates'])
assert multi_polygon.is_valid
示例2: mpoly
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import MultiPolygon [as 别名]
def mpoly(self):
"""Output of GeoJSON MultiPolygon object."""
return MultiPolygon(coordinates=self.coords)
示例3: geometry
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import MultiPolygon [as 别名]
def geometry(self):
try:
if self.type() == 'node':
if not self.lon() or not self.lat():
self._raiseException('Cannot build geometry: geometry information not included.')
return geojson.Point((self.lon(), self.lat()))
elif self.type() == 'way':
if not self.__getElement('geometry'):
self._raiseException('Cannot build geometry: geometry information not included.')
cs = self.__geometry_csToList(self.__getElement('geometry'))
if self.__geometry_equal(cs[0], cs[-1]):
return geojson.Polygon([cs])
else:
return geojson.LineString(cs)
elif self.type() == 'relation':
members = copy.deepcopy(self.__members())
membersOuter = self.__geometry_extract(members, 'outer')
if len(membersOuter) == 0:
self._raiseException('Cannot build geometry: no outer rings found.')
membersInner = self.__geometry_extract(members, 'inner')
ringsOuter = self.__geometry_buildRings(membersOuter)
ringsInner = self.__geometry_buildRings(membersInner)
ringsOuter = self.__geometry_orientRings(ringsOuter, positive=True)
ringsInner = self.__geometry_orientRings(ringsInner, positive=False)
polygons = self.__geometry_buildPolygons(ringsOuter, ringsInner)
if len(polygons) > 1:
return geojson.MultiPolygon(polygons)
else:
return geojson.Polygon(polygons[0])
else:
self._raiseException('Cannot build geometry: type of element unknown.')
except Exception as e:
_extendAndRaiseException(e, ' ({}/{})'.format(self.type(), self.id()))
示例4: _as_geojson
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import MultiPolygon [as 别名]
def _as_geojson(self, elements):
features = []
geometry = None
for elem in elements:
elem_type = elem.get("type")
elem_tags = elem.get("tags")
elem_geom = elem.get("geometry", [])
if elem_type == "node":
# Create Point geometry
geometry = geojson.Point((elem.get("lon"), elem.get("lat")))
elif elem_type == "way":
# Create LineString geometry
geometry = geojson.LineString([(coords["lon"], coords["lat"]) for coords in elem_geom])
elif elem_type == "relation":
# Initialize polygon list
polygons = []
# First obtain the outer polygons
for member in elem.get("members", []):
if member["role"] == "outer":
points = [(coords["lon"], coords["lat"]) for coords in member.get("geometry", [])]
# Check that the outer polygon is complete
if points and points[-1] == points[0]:
polygons.append([points])
else:
raise UnknownOverpassError("Received corrupt data from Overpass (incomplete polygon).")
# Then get the inner polygons
for member in elem.get("members", []):
if member["role"] == "inner":
points = [(coords["lon"], coords["lat"]) for coords in member.get("geometry", [])]
# Check that the inner polygon is complete
if points and points[-1] == points[0]:
# We need to check to which outer polygon the inner polygon belongs
point = Point(points[0])
check = False
for poly in polygons:
polygon = Polygon(poly[0])
if polygon.contains(point):
poly.append(points)
check = True
break
if not check:
raise UnknownOverpassError("Received corrupt data from Overpass (inner polygon cannot "
"be matched to outer polygon).")
else:
raise UnknownOverpassError("Received corrupt data from Overpass (incomplete polygon).")
# Finally create MultiPolygon geometry
if polygons:
geometry = geojson.MultiPolygon(polygons)
else:
raise UnknownOverpassError("Received corrupt data from Overpass (invalid element).")
if geometry:
feature = geojson.Feature(
id=elem["id"],
geometry=geometry,
properties=elem_tags
)
features.append(feature)
return geojson.FeatureCollection(features)