当前位置: 首页>>代码示例>>Python>>正文


Python geojson.Polygon方法代码示例

本文整理汇总了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) 
开发者ID:mapbox,项目名称:robosat,代码行数:21,代码来源:parking.py

示例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) 
开发者ID:mapbox,项目名称:robosat,代码行数:23,代码来源:building.py

示例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) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:26,代码来源:contour.py

示例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 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:20,代码来源:test_geocoding.py

示例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') 
开发者ID:cmla,项目名称:tsd,代码行数:19,代码来源:utils.py

示例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) 
开发者ID:cmla,项目名称:tsd,代码行数:24,代码来源:utils.py

示例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 
开发者ID:cmla,项目名称:tsd,代码行数:22,代码来源:utils.py

示例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) 
开发者ID:DigitalGlobe,项目名称:mltools,代码行数:35,代码来源:geojson_tools.py

示例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) 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:5,代码来源:jsoncodec.py

示例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) 
开发者ID:smartsdk,项目名称:ngsi-timeseries-api,代码行数:5,代码来源:jsoncodec.py

示例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') 
开发者ID:MetOffice,项目名称:forest,代码行数:10,代码来源:rdt.py

示例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)) 
开发者ID:developmentseed,项目名称:label-maker,代码行数:10,代码来源:test_filter.py

示例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)) 
开发者ID:developmentseed,项目名称:label-maker,代码行数:10,代码来源:test_filter.py

示例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"') 
开发者ID:developmentseed,项目名称:label-maker,代码行数:6,代码来源:test_filter.py

示例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\']') 
开发者ID:developmentseed,项目名称:label-maker,代码行数:6,代码来源:test_filter.py


注:本文中的geojson.Polygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。