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


Python geojson.Feature方法代码示例

本文整理汇总了Python中geojson.Feature方法的典型用法代码示例。如果您正苦于以下问题:Python geojson.Feature方法的具体用法?Python geojson.Feature怎么用?Python geojson.Feature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geojson的用法示例。


在下文中一共展示了geojson.Feature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: way

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [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 Feature [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 Feature [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: to_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def to_geojson(products):
        """Return the products from a query response as a GeoJSON with the values in their
        appropriate Python types.
        """
        feature_list = []
        for i, (product_id, props) in enumerate(products.items()):
            props = props.copy()
            props["id"] = product_id
            poly = geomet.wkt.loads(props["footprint"])
            del props["footprint"]
            del props["gmlfootprint"]
            # Fix "'datetime' is not JSON serializable"
            for k, v in props.items():
                if isinstance(v, (date, datetime)):
                    props[k] = v.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
            feature_list.append(geojson.Feature(geometry=poly, id=i, properties=props))
        return geojson.FeatureCollection(feature_list) 
开发者ID:sentinelsat,项目名称:sentinelsat,代码行数:19,代码来源:sentinel.py

示例5: createGeojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def createGeojson(geocoder, locations):
        """Create geojson for given locations and geocoder url"""

        geoms = []

        for i in locations:
            wkt = Geocoder.getWktFromGeocoder(geocoder, i)
            geom = Geocoder.createGeometryFromWkt(wkt)
            try:
                for g in geom:
                    geoms.append(geojson.Feature(geometry=g,
                                                 properties={'location': i}))
            except TypeError:
                geoms.append(geojson.Feature(geometry=geom,
                                             properties={'location': i}))
        multiPoly = geojson.FeatureCollection(geoms)

        return multiPoly 
开发者ID:Kitware,项目名称:minerva,代码行数:20,代码来源:geocoder.py

示例6: _flatten

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def _flatten(features):
    r"""Expand all MultiLineString features in the input list to individual
    LineString features"""
    flat_features = []
    for feature in features:
        if feature['geometry']['type'] == 'LineString':
            flat_features.append(feature)
        if feature['geometry']['type'] == 'MultiLineString':
            properties = feature['properties']
            for line_string in feature['geometry']['coordinates']:
                geometry = geojson.LineString(coordinates=line_string)
                flat_feature = geojson.Feature(geometry=geometry,
                                               properties=properties)
                flat_features.append(flat_feature)

    return flat_features 
开发者ID:icepack,项目名称:icepack,代码行数:18,代码来源:meshing.py

示例7: createGeoJSON

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def createGeoJSON(self):
        """ Get list of link geometries and properties to be converted.
            Input: Vissim object
            Output: list of links
        """
        features = []
        for link in self.data.xpath('./links/link'):
            geos = []
            linkNum = link.attrib['no']
            for geo in link.xpath('./geometry/points3D/point3D'):
                x, y = geo.attrib['x'], geo.attrib['y']
                latLng = self.scaledMetersToNode((x, y))
                geos.append(latLng)
            linkNum = link.attrib['no']
            laneNum = str(len(link.xpath('./lanes/lane')))
            multiLine = geojson.MultiLineString(coordinates=geos)
            features.append(geojson.Feature(id=linkNum, geometry=multiLine,
                                            properties={'lane': laneNum,
                                                        'id': linkNum}))
        return geojson.FeatureCollection(features) 
开发者ID:brianhuey,项目名称:vissim,代码行数:22,代码来源:vissim_to_geojson.py

示例8: geojson_feature

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def geojson_feature(self):
        return Feature(
            geometry=loads(self.location.geojson),
            id='Incident:{pk}'.format(pk=self.pk),
            properties={
                'name': self.name,
                'description': self.description,
                'severity': self.get_severity_display(),
                'created': str(self.created),
                'closed': self.closed,
                'model': 'Incident',
                'pk': self.pk,
                'url': reverse('tracker:incident-detail', kwargs={'pk': self.pk}),
            }
        ) 
开发者ID:abarto,项目名称:tracker_project,代码行数:17,代码来源:models.py

示例9: campaign_visits_to_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def campaign_visits_to_geojson(rpc, campaign_id, geojson_file):
	"""
	Export the geo location information for all the visits of a campaign into
	the `GeoJSON <http://geojson.org/>`_ format.

	:param rpc: The connected RPC instance to load the information with.
	:type rpc: :py:class:`.KingPhisherRPCClient`
	:param campaign_id: The ID of the campaign to load the information for.
	:param str geojson_file: The destination file for the GeoJSON data.
	"""
	ips_for_georesolution = {}
	ip_counter = collections.Counter()
	for visit_node in _get_graphql_campaign_visits(rpc, campaign_id):
		visit = visit_node['node']
		ip_counter.update((visit['ip'],))
		visitor_ip = ipaddress.ip_address(visit['ip'])
		if not isinstance(visitor_ip, ipaddress.IPv4Address):
			continue
		if visitor_ip.is_loopback or visitor_ip.is_private:
			continue
		if not visitor_ip in ips_for_georesolution:
			ips_for_georesolution[visitor_ip] = visit['firstSeen']
		elif ips_for_georesolution[visitor_ip] > visit['firstSeen']:
			ips_for_georesolution[visitor_ip] = visit['firstSeen']
	ips_for_georesolution = [ip for (ip, _) in sorted(ips_for_georesolution.items(), key=lambda x: x[1])]
	locations = {}
	for ip_addresses in iterutils.chunked(ips_for_georesolution, 50):
		locations.update(rpc.geoip_lookup_multi(ip_addresses))
	points = []
	for ip, location in locations.items():
		if not (location.coordinates and location.coordinates[0] and location.coordinates[1]):
			continue
		points.append(geojson.Feature(geometry=location, properties={'count': ip_counter[ip], 'ip-address': ip}))
	feature_collection = geojson.FeatureCollection(points)
	with open(geojson_file, 'w') as file_h:
		serializers.JSON.dump(feature_collection, file_h, pretty=True) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:38,代码来源:export.py

示例10: contour_to_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def contour_to_geojson(contour, geojson_filepath=None, min_angle_deg=None,
                       ndigits=5, unit='', stroke_width=1, geojson_properties=None, strdump=False,
                       serialize=True):
    """Transform matplotlib.contour to geojson."""
    collections = contour.collections
    contour_index = 0
    line_features = []
    for collection in collections:
        color = collection.get_edgecolor()
        for path in collection.get_paths():
            v = path.vertices
            if len(v) < 3:
                continue
            coordinates = keep_high_angle(v, min_angle_deg) if min_angle_deg else v
            coordinates = np.around(coordinates, ndigits) if ndigits is not None else coordinates
            line = LineString(coordinates.tolist())
            properties = {
                "stroke-width": stroke_width,
                "stroke": rgb2hex(color[0]),
                "title": "%.2f" % contour.levels[contour_index] + ' ' + unit,
                "level-value": float("%.6f" % contour.levels[contour_index]),
                "level-index": contour_index
            }
            if geojson_properties:
                properties.update(geojson_properties)
            line_features.append(Feature(geometry=line, properties=properties))
        contour_index += 1
    feature_collection = FeatureCollection(line_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:31,代码来源:contour.py

示例11: contourf_to_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def contourf_to_geojson(contourf, geojson_filepath=None, min_angle_deg=None,
                        ndigits=5, unit='', stroke_width=1, fill_opacity=.9, fill_opacity_range=None,
                        geojson_properties=None, strdump=False, serialize=True):
    """Transform matplotlib.contourf to geojson with MultiPolygons."""
    if fill_opacity_range:
        variable_opacity = True
        min_opacity, max_opacity = fill_opacity_range
        opacity_increment = (max_opacity - min_opacity) / len(contourf.levels)
        fill_opacity = min_opacity
    else:
        variable_opacity = False
    polygon_features = []
    contourf_levels = get_contourf_levels(contourf.levels, contourf.extend)
    for coll, level in zip(contourf.collections, contourf_levels):
        color = coll.get_facecolor()
        muli = MP(coll, min_angle_deg, ndigits)
        polygon = muli.mpoly()
        fcolor = rgb2hex(color[0])
        properties = set_contourf_properties(stroke_width, fcolor, fill_opacity, level, unit)
        if geojson_properties:
            properties.update(geojson_properties)
        feature = Feature(geometry=polygon, properties=properties)
        polygon_features.append(feature)
        if variable_opacity:
            fill_opacity += opacity_increment
    feature_collection = FeatureCollection(polygon_features)
    return _render_feature_collection(feature_collection, geojson_filepath, strdump, serialize) 
开发者ID:bartromgens,项目名称:geojsoncontour,代码行数:29,代码来源:contour.py

示例12: linkAndAssembleGeometry

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def linkAndAssembleGeometry(self, link, linkItemId, records):
        try:
            item = self.model('item').load(linkItemId, force=True)
            featureCollections = self.downloadDataset(item)
        except Exception:
            raise GirderException('Unable to load link target dataset.')

        valueLinks = sorted([x for x in link
                             if x['operator'] == '='])
        constantLinks = [x for x in link
                         if x['operator'] == 'constant']
        mappedGeometries = {}
        linkingDuplicateCount = 0
        for feature in featureCollections['features']:
            skipCurrentFeature = False
            for constantLink in constantLinks:
                if feature['properties'][constantLink['field']] != constantLink['value']:
                    # If the feature dones't satisfy any constant linking condition
                    skipCurrentFeature = True
                    break
            if skipCurrentFeature:
                continue
            try:
                key = ''.join([str(feature['properties'][x['field']]) for x in valueLinks])
            except KeyError:
                raise GirderException('missing property for key ' +
                                      x['field'] + ' in geometry link target geojson')
            if key in mappedGeometries:
                linkingDuplicateCount += 1
            mappedGeometries[key] = feature['geometry']

        assembled = []
        for record in records:
            key = ''.join([str(record[x['value']]) for x in valueLinks])
            if key in mappedGeometries:
                assembled.append(
                    geojson.Feature(geometry=mappedGeometries[key], properties=record)
                )
        return geojson.FeatureCollection(assembled), linkingDuplicateCount 
开发者ID:Kitware,项目名称:minerva,代码行数:41,代码来源:dataset.py

示例13: unwrapFeature

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def unwrapFeature(geometry):
    if geometry.type == 'FeatureCollection':
        geometries = [n.geometry for n in geometry.features]
        return geojson.GeometryCollection(geometries)
    elif geometry.type == 'Feature':
        return geometry.geometry
    else:
        return geometry 
开发者ID:Kitware,项目名称:minerva,代码行数:10,代码来源:dataset.py

示例14: _topologize

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def _topologize(input_features):
    r"""Return a FeatureCollection of MultiLineStrings, one for each loop"""
    loops = _features_to_loops(input_features)
    features = []
    for loop in loops:
        coords = [list(geojson.utils.coords(input_features[index]))
                  for index in loop]
        multi_line_string = geojson.MultiLineString(coords)
        features.append(geojson.Feature(geometry=multi_line_string))

    return features 
开发者ID:icepack,项目名称:icepack,代码行数:13,代码来源:meshing.py

示例15: needs_snapping

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import Feature [as 别名]
def needs_snapping():
    coords = [[(0., -1e-6), (1., 0.), (1., 1. - 1e-6)],
              [(1., 1. + 1e-6), (0., 1.), (0., 1e-6)]]
    multi_line_string = geojson.MultiLineString(coords, validate=True)
    feature = geojson.Feature(geometry=multi_line_string, properties={})
    return geojson.FeatureCollection([feature]) 
开发者ID:icepack,项目名称:icepack,代码行数:8,代码来源:meshing_test.py


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