本文整理汇总了Python中geojson.Polygon方法的典型用法代码示例。如果您正苦于以下问题:Python geojson.Polygon方法的具体用法?Python geojson.Polygon怎么用?Python geojson.Polygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geojson
的用法示例。
在下文中一共展示了geojson.Polygon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: way
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def way(self, w):
if not is_polygon(w):
return
if "amenity" not in w.tags or w.tags["amenity"] != "parking":
return
if "parking" in w.tags:
if w.tags["parking"] in self.parking_filter:
return
geometry = geojson.Polygon([[(n.lon, n.lat) for n in w.nodes]])
shape = shapely.geometry.shape(geometry)
if shape.is_valid:
feature = geojson.Feature(geometry=geometry)
self.storage.add(feature)
else:
print("Warning: invalid feature: https://www.openstreetmap.org/way/{}".format(w.id), file=sys.stderr)
示例2: way
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def way(self, w):
if not is_polygon(w):
return
if "building" not in w.tags:
return
if w.tags["building"] in self.building_filter:
return
if "location" in w.tags and w.tags["location"] in self.location_filter:
return
geometry = geojson.Polygon([[(n.lon, n.lat) for n in w.nodes]])
shape = shapely.geometry.shape(geometry)
if shape.is_valid:
feature = geojson.Feature(geometry=geometry)
self.storage.add(feature)
else:
print("Warning: invalid feature: https://www.openstreetmap.org/way/{}".format(w.id), file=sys.stderr)
示例3: contourf_to_geojson_overlap
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def contourf_to_geojson_overlap(contourf, geojson_filepath=None, min_angle_deg=None,
ndigits=5, unit='', stroke_width=1, fill_opacity=.9,
geojson_properties=None, strdump=False, serialize=True):
"""Transform matplotlib.contourf to geojson with overlapping filled contours."""
polygon_features = []
contourf_idx = 0
contourf_levels = get_contourf_levels(contourf.levels, contourf.extend)
for collection in contourf.collections:
color = collection.get_facecolor()
for path in collection.get_paths():
for coord in path.to_polygons():
if min_angle_deg:
coord = keep_high_angle(coord, min_angle_deg)
coord = np.around(coord, ndigits) if ndigits else coord
polygon = Polygon(coordinates=[coord.tolist()])
fcolor = rgb2hex(color[0])
properties = set_contourf_properties(stroke_width, fcolor, fill_opacity, contourf_levels[contourf_idx], unit)
if geojson_properties:
properties.update(geojson_properties)
feature = Feature(geometry=polygon, properties=properties)
polygon_features.append(feature)
contourf_idx += 1
feature_collection = FeatureCollection(polygon_features)
return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize)
示例4: test_entity_add_city_shape
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def test_entity_add_city_shape(air_quality_observed):
air_quality_observed.pop('location')
air_quality_observed['address']['value'] = {
"addressCountry": "MX",
"addressLocality": "Ciudad de México",
}
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'] == 'Polygon'
polygon = geojson.Polygon(geo['coordinates'])
assert polygon.is_valid
示例5: valid_geojson
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def valid_geojson(filepath):
"""
Check if a file contains valid geojson.
"""
with open(filepath, 'r') as f:
geo = geojson.load(f)
if type(geo) == geojson.geometry.Polygon:
return geo
if type(geo) == geojson.feature.Feature:
p = geo['geometry']
if type(p) == geojson.geometry.Polygon:
return p
if type(geo) == geojson.feature.FeatureCollection:
p = geo['features'][0]['geometry']
if type(p) == geojson.geometry.Polygon:
return p
raise argparse.ArgumentTypeError('Invalid geojson: only polygons are supported')
示例6: bounding_box_of_projected_aoi
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def bounding_box_of_projected_aoi(rpc, aoi, z=0, homography=None):
"""
Return the x, y, w, h pixel bounding box of a projected AOI.
Args:
rpc (rpcm.RPCModel): RPC camera model
aoi (geojson.Polygon): GeoJSON polygon representing the AOI
z (float): altitude of the AOI with respect to the WGS84 ellipsoid
homography (2D array, optional): matrix of shape (3, 3) representing an
homography to be applied to the projected points before computing
their bounding box.
Return:
x, y (ints): pixel coordinates of the top-left corner of the bounding box
w, h (ints): pixel dimensions of the bounding box
"""
lons, lats = np.array(aoi['coordinates'][0]).T
x, y = rpc.projection(lons, lats, z)
pts = list(zip(x, y))
if homography is not None:
pts = points_apply_homography(homography, pts)
return np.round(bounding_box2D(pts)).astype(int)
示例7: crop_aoi
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def crop_aoi(geotiff, aoi, z=0):
"""
Crop a geographic AOI in a georeferenced image using its RPC functions.
Args:
geotiff (string): path or url to the input GeoTIFF image file
aoi (geojson.Polygon): GeoJSON polygon representing the AOI
z (float, optional): base altitude with respect to WGS84 ellipsoid (0
by default)
Return:
crop (array): numpy array containing the cropped image
x, y, w, h (ints): image coordinates of the crop. x, y are the
coordinates of the top-left corner, while w, h are the dimensions
of the crop.
"""
x, y, w, h = bounding_box_of_projected_aoi(rpcm.rpc_from_geotiff(geotiff), aoi, z)
with rasterio.open(geotiff) as src:
crop = rasterio_window_crop(src, x, y, w, h)
return crop, x, y
示例8: write_to
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def write_to(data, property_names, output_file):
'''
Write list of tuples to geojson.
First entry of each tuple should be geometry in hex coordinates
and the rest properties.
Args:
data: List of tuples.
property_names: List of strings. Should be same length as the
number of properties.
output_file (str): Output file name.
'''
geojson_features = []
for entry in data:
coords_in_hex, properties = entry[0], entry[1:]
geometry = loads(coords_in_hex, hex=True)
property_dict = dict(zip(property_names, properties))
if geometry.geom_type == 'Polygon':
coords = [list(geometry.exterior.coords)] # brackets required
geojson_feature = geojson.Feature(geometry=geojson.Polygon(coords),
properties=property_dict)
elif geometry.geom_type == 'Point':
coords = list(geometry.coords)[0]
geojson_feature = geojson.Feature(geometry=geojson.Point(coords),
properties=property_dict)
geojson_features.append(geojson_feature)
feature_collection = geojson.FeatureCollection(geojson_features)
with open(output_file, 'wb') as f:
geojson.dump(feature_collection, f)
示例9: polygon_to_json_rep
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def polygon_to_json_rep(polygon: SlfPolygon) -> Polygon:
ps = list_point_tuples(polygon)
return Polygon(ps)
示例10: box_to_json_rep
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def box_to_json_rep(box: SlfBox) -> Polygon:
ps = list_point_tuples(box.to_polygon())
return Polygon(ps)
示例11: load_polygon_netcdf
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def load_polygon_netcdf(path):
"""
Loads polygons from netcdf
:param path: absolute path and filename
:return: geojson object for plotting in bokeh
"""
return getRDT(path, 0, 'Polygon')
示例12: test_geometry_comparison
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def test_geometry_comparison(self):
"""Test $type specific filters for comparison"""
ff = create_filter(['==', '$type', 'Polygon'])
# print(_compile(['==', '$type', 'Polygon']))
passing = Feature(geometry=polygon_geometry)
failing = Feature(geometry=line_geometry)
self.assertTrue(ff(passing))
self.assertFalse(ff(failing))
示例13: test_geometry_in
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def test_geometry_in(self):
"""Test $type specific filters for inclusion"""
ff = create_filter(['in', '$type', 'Point', 'Polygon'])
# print(_compile(['in', '$type', 'Point', 'Polygon']))
passing = Feature(geometry=polygon_geometry)
failing = Feature(geometry=line_geometry)
self.assertTrue(ff(passing))
self.assertFalse(ff(failing))
示例14: test_compile_comparison_op
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def test_compile_comparison_op(self):
"""Test private function _compile_comparison_op"""
self.assertEqual(_compile_comparison_op('a', 5, '=='), 'p.get("a")==5')
self.assertEqual(_compile_comparison_op('$type', 'Polygon', '=='), 'f.get("geometry").get("type")=="Polygon"')
示例15: test_compile_in_op
# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Polygon [as 别名]
def test_compile_in_op(self):
"""Test private function _compile_in_op"""
self.assertEqual(_compile_in_op('a', ['a', 'b']), 'p.get("a") in [\'a\', \'b\']')
self.assertEqual(_compile_in_op('$type', ['Point', 'Polygon']), 'f.get("geometry").get("type") in [\'Point\', \'Polygon\']')