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


Python geojson.FeatureCollection方法代码示例

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


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

示例1: contourf_to_geojson_overlap

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

示例2: to_geojson

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

示例3: createGeojson

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

示例4: split

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [as 别名]
def split(input_file, file_1, file_2, no_in_first_file):
    '''
    Split a geojson in two separate files.

       Args:
           input_file (str): Input filename.
           file_1 (str): Output file name 1.
           file_2 (str): Output file name 2.
           no_features (int): Number of features in input_file to go to file_1.
           output_file (str): Output file name.
    '''

    # get feature collection
    with open(input_file) as f:
        feat_collection = geojson.load(f)

    features = feat_collection['features']
    feat_collection_1 = geojson.FeatureCollection(features[0:no_in_first_file])
    feat_collection_2 = geojson.FeatureCollection(features[no_in_first_file:])

    with open(file_1, 'w') as f:
        geojson.dump(feat_collection_1, f)

    with open(file_2, 'w') as f:
        geojson.dump(feat_collection_2, f) 
开发者ID:DigitalGlobe,项目名称:mltools,代码行数:27,代码来源:geojson_tools.py

示例5: force_route_mid_point

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [as 别名]
def force_route_mid_point(request, **kwargs):
    """
    Force a route over a middle point such as a front office
    :return: a single GeoJSON featureCollection with a middle point
    :param
    """
    start_node = request.GET.get('startnode', 1)  # 1385
    mnode = request.GET.get('midnode', 1)  # 1167
    end_node = request.GET.get('endnode', 1)  # 1252

    # building_id = 1
    route_nodes = {'building-id': 1, 'start-node-id': start_node, 'mid-node-id': mnode, 'end-node-id': end_node}

    # remove last coordinate of first route
    start_node_id = get_room_centroid_node(route_nodes['start-node-id'])
    mid_node_id = get_room_centroid_node(route_nodes['mid-node-id'])
    end_node_id = get_room_centroid_node(route_nodes['end-node-id'])

    route_start_to_mid_point = run_route(start_node_id, mid_node_id, 1)
    route_mid_to_end_point = run_route(mid_node_id, end_node_id, 1)

    route_out_merge = merge_2_routes(route_start_to_mid_point, route_mid_to_end_point)

    return Response({'type': 'FeatureCollection', 'features': route_out_merge}) 
开发者ID:indrz,项目名称:indrz,代码行数:26,代码来源:views.py

示例6: createGeoJSON

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

示例7: get

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [as 别名]
def get(self, request, *args, **kwargs):
        features = [incident.geojson_feature for incident in Incident.objects.filter(closed=False)]
        feature_collection = FeatureCollection(features)

        return self.render_json_response(feature_collection) 
开发者ID:abarto,项目名称:tracker_project,代码行数:7,代码来源:views.py

示例8: save

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [as 别名]
def save(self, out):
        collection = geojson.FeatureCollection(self.features)

        with open(out, "w") as fp:
            geojson.dump(collection, fp) 
开发者ID:mapbox,项目名称:robosat,代码行数:7,代码来源:parking.py

示例9: flush

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [as 别名]
def flush(self):
        if not self.features:
            return

        collection = geojson.FeatureCollection(self.features)

        base, ext = os.path.splitext(self.out)
        suffix = uuid.uuid4().hex

        out = "{}-{}{}".format(base, suffix, ext)

        with open(out, "w") as fp:
            geojson.dump(collection, fp)

        self.features.clear() 
开发者ID:mapbox,项目名称:robosat,代码行数:17,代码来源:core.py

示例10: campaign_visits_to_geojson

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

示例11: contour_to_geojson

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

示例12: contourf_to_geojson

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

示例13: linkAndAssembleGeometry

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

示例14: unwrapFeature

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

示例15: needs_snapping

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import FeatureCollection [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.FeatureCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。