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


Python geojson.loads方法代码示例

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


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

示例1: downloadDataset

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def downloadDataset(self, item, funcAllowed=False):
        minervaMeta = item['meta']['minerva']
        if not minervaMeta.get('postgresGeojson'):
            fileId = None
            # The storing of file id on item is a little bit messy, so multiple place
            # needs to be checked
            if 'original_files' in minervaMeta:
                fileId = minervaMeta['original_files'][0]['_id']
            elif 'geojson_file' in minervaMeta:
                fileId = minervaMeta['geojson_file']['_id']
            else:
                fileId = minervaMeta['geo_render']['file_id']
            file = self.model('file').load(fileId, force=True)
            result = self.model('file').download(file, headers=False)
        else:
            result = self._getPostgresGeojsonData(item)
        if not callable(result) or funcAllowed:
            return result
        return geojson.loads(''.join(list(result()))) 
开发者ID:Kitware,项目名称:minerva,代码行数:21,代码来源:dataset.py

示例2: _getPostgresGeojsonData

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def _getPostgresGeojsonData(self, item):
        user = self.getCurrentUser()
        minervaMeta = item['meta']['minerva']
        file = self.model('file').load(minervaMeta['geo_render']['file_id'], user=user)
        assetstore = self.model('assetstore').load(file['assetstoreId'])
        adapter = assetstore_utilities.getAssetstoreAdapter(assetstore)
        func = adapter.downloadFile(
            file, offset=0, headers=False, endByte=None,
            contentDisposition=None, extraParameters=None)

        geometryField = item['meta']['minerva']['postgresGeojson']['geometryField']

        if geometryField['type'] == 'built-in':
            return func
        elif geometryField['type'] == 'link':
            records = json.loads(''.join(list(func())))
            featureCollection, _ = self.linkAndAssembleGeometry(
                geometryField['links'], geometryField['itemId'], records)
            if len(featureCollection.features) == 0:
                raise GirderException('Dataset is empty')
            return featureCollection 
开发者ID:Kitware,项目名称:minerva,代码行数:23,代码来源:dataset.py

示例3: read_report_dir

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def read_report_dir(rptdir, total_parcel_count=0):
    #rpt dir passed in, just read the preprossed report data
    rpt = FloodReport()
    rpt.total_parcel_count = total_parcel_count
    rpt.model = swmmio.Model(os.path.dirname(rptdir))
    rpt.scenario = rpt.model.scenario
    rpt.parcel_flooding = pd.read_csv(os.path.join(rptdir,
                                                   'parcel_flood_comparison.csv'))
    rpt.parcel_hrs_flooded = rpt.parcel_flooding.HoursFloodedProposed.sum()
    rpt.parcel_vol_flooded = rpt.parcel_flooding.TotalFloodVolProposed.sum()
    costcsv = os.path.join(rptdir, 'cost_estimate.csv')
    conduits_geojson_path = os.path.join(rptdir, 'new_conduits.json')

    if os.path.exists(costcsv):
        #calc the cost estimate total in millions
        cost_df =  pd.read_csv(costcsv)
        rpt.cost_estimate = cost_df.TotalCostEstimate.sum() / math.pow(10, 6)

    if os.path.exists(conduits_geojson_path):
        with open (conduits_geojson_path, 'r') as f:
            rpt.new_conduits_geojson = geojson.loads(f.read())

    return rpt 
开发者ID:aerispaha,项目名称:swmmio,代码行数:25,代码来源:reporting.py

示例4: geojson_feature

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

示例5: within_area

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def within_area(flight, area_geojson_location):
      if not area_geojson_location:
        return True
      try:
        with open(path.expanduser(area_geojson_location), 'r') as geo:
          bounds = geojson.loads(geo.read())["features"][0]["geometry"]
          flight_loc = Point(f.get("lon", 0), f.get("lat", 0))
          return shape(bounds).contains(flight_loc)
      except IOError:
        print("couldn't find geojson file at %s, ignoring" % area_geojson_location, file=stderr)
        return True 
开发者ID:jeremybmerrill,项目名称:flyover,代码行数:13,代码来源:dump1090_to_nearest_flight.py

示例6: test_footprints_s1

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def test_footprints_s1(api, test_wkt, read_fixture_file):
    products = api.query(
        test_wkt, (datetime(2014, 10, 10), datetime(2014, 12, 31)), producttype="GRD"
    )

    footprints = api.to_geojson(products)
    for footprint in footprints["features"]:
        assert not footprint["geometry"].errors()

    expected_footprints = geojson.loads(read_fixture_file("expected_search_footprints_s1.geojson"))
    # to compare unordered lists (JSON objects) they need to be sorted or changed to sets
    assert set(footprints) == set(expected_footprints) 
开发者ID:sentinelsat,项目名称:sentinelsat,代码行数:14,代码来源:test_geographic.py

示例7: test_footprints_s2

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def test_footprints_s2(products, fixture_path):
    footprints = SentinelAPI.to_geojson(products)
    for footprint in footprints["features"]:
        assert not footprint["geometry"].errors()

    with open(fixture_path("expected_search_footprints_s2.geojson")) as geojson_file:
        expected_footprints = geojson.loads(geojson_file.read())
    # to compare unordered lists (JSON objects) they need to be sorted or changed to sets
    assert set(footprints) == set(expected_footprints) 
开发者ID:sentinelsat,项目名称:sentinelsat,代码行数:11,代码来源:test_geographic.py

示例8: process_formdata

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def process_formdata(self, valuelist):
        if valuelist:
            value = valuelist[0]
            try:
                if isinstance(value, str):
                    self.data = geojson.loads(value)
                else:
                    self.data = geojson.GeoJSON.to_instance(value)
            except:
                self.data = None
                log.exception('Unable to parse GeoJSON')
                raise ValueError(self.gettext('Not a valid GeoJSON')) 
开发者ID:opendatateam,项目名称:udata,代码行数:14,代码来源:forms.py

示例9: parse_geometry

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def parse_geometry(geometry_raw, rewrite_circle=False):


    geometry_statement = None
    # is it WKT?
    try:
        geometry_statement = sqlalchemy.sql.expression.func.GeomFromText(
            geomet.wkt.dumps(geomet.wkt.loads(geometry_raw)))
    except ValueError as err:
        logging.debug('    ... not WKT')
    # is it GeoJSON?
    if not geometry_statement:
        try:
            geometry_statement = sqlalchemy.sql.expression.func.GeomFromText(
                geomet.wkt.dumps(geojson.loads(geometry_raw)))
        except ValueError as err:
            logging.debug('    ... not GeoJSON')
    if not geometry_statement and rewrite_circle and 'CIRCLE' in geometry_raw:
        # now see if it a CIRCLE(long lat, rad_in_m)
        re_res = re.findall(
            r'CIRCLE\s*\(\s*([0-9.-]+)\s+([0-9.-]+)\s*,\s*([0-9.]+)\s*\)',
            geometry_raw)
        if re_res and len(re_res[0]) == 3:
            lng = float(re_res[0][0])
            lat = float(re_res[0][1])
            rad = float(re_res[0][2])
            geometry_statement = sqlalchemy.sql.expression.func.Buffer(
                sqlalchemy.sql.expression.func.POINT(lng, lat),
                rad / 1000 / 111.045)
        else:
            logging.warn('ignoring malformed intersects statement:%s',
                         geometry_raw)
    logging.info('%s becomes %s', geometry_raw, geometry_statement)
    return geometry_statement 
开发者ID:google,项目名称:jacs,代码行数:36,代码来源:geometry_util.py

示例10: create_layer_from_layer_selection

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def create_layer_from_layer_selection(self, params):
        """
            Used to create a new Layer from the current LayerSelection features
        :param params:
        :return:
        """
        # Resolve the source layer from the layer_selection__id
        source_layer = self.resolve_layer(params)
        config_entity = source_layer.config_entity
        db_entity = source_layer.db_entity_interest.db_enitty
        feature_class = FeatureClassCreator(config_entity, db_entity).dynamic_model_class()
        layer = Layer.objects.get(presentation__config_entity=config_entity, db_entity_key=db_entity.key)
        layer_selection = get_or_create_layer_selection_class_for_layer(layer, config_entity, False).objects.all()[0]
        # TODO no need to do geojson here
        feature_dict = dict(
            type="Feature"
        )
        feature_dicts = map(lambda feature:
                            deep_merge(feature_dict, {"geometry":geojson.loads(feature.wkb_geometry.json)}),
                            layer_selection.selected_features or feature_class.objects.all())
        json = dict({"type": "FeatureCollection", "features": feature_dicts})
        db_entity_configuration = update_or_create_db_entity(config_entity, **dict(
            class_scope=FutureScenario,
            name='Import From Selection Test',
            key='import_selection_test',
            url='file://notusingthis'
        ))
        self.make_geojson_db_entity(config_entity, db_entity_configuration, data=json) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:30,代码来源:layer_selection_resource.py

示例11: bounds

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def bounds(self):
        """
            Always the same as the geometry field for read-access
        :return:
        """
        return loads(self.geometry.json) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:8,代码来源:layer_selection.py

示例12: importer

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def importer(self, config_entity, db_entity, **kwargs):
        """
            Creates various GeojsonFeature classes by importing geojson and saving it to the database via a dynamic subclass of GeojsonFeature
        :schema: The optional schema to use for the dynamic subclass's meta db_table attribute, which will allow the class's table to be saved in the specified schema. Defaults to public
        :data: Optional python dict data to use instead of loading from the db_entity.url
        :return: a list of lists. Each list is a list of features of distinct subclass of GeoJsonFeature that is created dynamically. To persist these features, you must first create the subclass's table in the database using create_table_for_dynamic_class(). You should also register the table as a DbEntity.
        """
        if self.seed_data:
            data = geojson.loads(jsonify(self.seed_data), object_hook=geojson.GeoJSON.to_instance)
        else:
            fp = open(db_entity.url.replace('file://', ''))
            data = geojson.load(fp, object_hook=geojson.GeoJSON.to_instance)
        feature_class_creator = FeatureClassCreator(config_entity, db_entity)
        # find all unique properties
        feature_class_configuration = feature_class_creator.feature_class_configuration_from_geojson_introspection(data)
        feature_class_creator.update_db_entity(feature_class_configuration)
        feature_class = feature_class_creator.dynamic_model_class(base_only=True)
        # Create our base table. Normally this is done by the import, but we're just importing into memory
        create_tables_for_dynamic_classes(feature_class)
        # Now write each feature to our newly created table
        for feature in map(lambda feature: self.instantiate_sub_class(feature_class, feature), data.features):
            feature.save()
        # Create the rel table too
        rel_feature_class = feature_class_creator.dynamic_model_class()
        create_tables_for_dynamic_classes(rel_feature_class)

        # PostGIS 2 handles this for us now
        # if InformationSchema.objects.table_exists(db_entity.schema, db_entity.table):
        #     # Tell PostGIS about the new geometry column or the table
        #     sync_geometry_columns(db_entity.schema, db_entity.table)

        # Create association classes and tables and populate them with data
        create_and_populate_relations(config_entity, db_entity) 
开发者ID:CalthorpeAnalytics,项目名称:urbanfootprint,代码行数:35,代码来源:geo_json_processor.py

示例13: test_valid_flows_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def test_valid_flows_geojson(exemplar_spatial_unit_param):
    """
    Check that valid geojson is returned for Flows.

    """
    if not exemplar_spatial_unit_param.has_geography:
        pytest.skip("Query with spatial_unit=CellSpatialUnit() has no geometry.")
    dl = daily_location("2016-01-01", spatial_unit=exemplar_spatial_unit_param)
    dl2 = daily_location("2016-01-02", spatial_unit=exemplar_spatial_unit_param)
    fl = Flows(dl, dl2)
    assert geojson.loads(fl.to_geojson_string()).is_valid 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:13,代码来源:test_flows.py

示例14: test_valid_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def test_valid_geojson(exemplar_spatial_unit_param):
    """
    Check that valid geojson is returned.

    """
    if not exemplar_spatial_unit_param.has_geography:
        pytest.skip("Query with spatial_unit=CellSpatialUnit() has no geometry.")
    dl = daily_location(
        "2016-01-01", "2016-01-02", spatial_unit=exemplar_spatial_unit_param
    ).aggregate()
    assert geojson.loads(dl.to_geojson_string()).is_valid 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:13,代码来源:test_geomixin.py

示例15: test_valid_geojson

# 需要导入模块: import geojson [as 别名]
# 或者: from geojson import loads [as 别名]
def test_valid_geojson(make_spatial_unit_params):
    """
    Check that valid geojson is returned.
    """
    spatial_unit = make_spatial_unit(**make_spatial_unit_params)
    geo = Geography(spatial_unit)
    assert geojson.loads(geo.to_geojson_string()).is_valid 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:9,代码来源:test_spatial_geography.py


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