How to use the geojson.dump function in geojson

To help you get started, we’ve selected a few geojson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jazzband / geojson / tests / test_features.py View on Github external
def test_unicode_properties(self):
        with open("tests/data.geojson") as file_:
            obj = geojson.load(file_)
        geojson.dump(obj, StringIO())
github erdc / quest / dsl / io / vitd.py View on Github external
'name': name,
                            'parameter': parameter,
                            'metadata': metadata,
                            'unit_of_measurement': unit,
                            'time': df.index.to_native_types(),
                            'values': df.values.tolist(),
                        },
                    )
        if not path.endswith('.json'):
            path += '.json'

        base, fname = os.path.split(path)
        util.mkdir_if_doesnt_exist(base)

        with open(path, 'w') as f:
            dump(feature, f)

        print('file written to: %s' % path)
github hotosm / MapCampaigner / lambda_functions / process / make_mbtiles / lambda_function.py View on Github external
'campaign_uuid': uuid,
            'index': index,
            'zoom_levels': zoom_levels
        }

        # Run lambda function that fetches tiles.
        spawn_fetch_tiles(event)

    # Save new geojson.
    tiles_file = 'tiles.geojson'
    logging.info('Saving hashes to {0}'.format(tiles_file))
    feature_collection = gj.FeatureCollection(features)

    geojson_outfile = join(folder_path, '{0}'.format(tiles_file))
    with open(geojson_outfile, 'w') as f:
        gj.dump(feature_collection, f)

    save_to_s3(client, uuid)
github DigitalGlobe / mltools / polygon_pipeline.py View on Github external
train_out = 'train_{}'.format(output_name + '.geojson')
        test_size = int(train_test * len(final))
        test = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final[:test_size]}
        train = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final[test_size:]}

        # save train and test geojsons
        with open(test_out, 'wb') as f1:
            geojson.dump(test, f1)
        print 'Test polygons saved as {}'.format(test_out)

        with open(train_out, 'wb') as f2:
            geojson.dump(train, f2)
        print 'Train polygons saved as {}'.format(train_out)

    else:  # only save one file with balanced classes
        balanced_json = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final}
        with open(output_name + '.geojson', 'wb') as f:
            geojson.dump(balanced_json, f)
        print '{} polygons saved as {}.geojson'.format(len(final), output_name)
github erdc / quest / dsl / services / usgs_eros.py View on Github external
selected = [feature for feature in metadata['features'] if feature['id'] in locations]
            return FeatureCollection(selected)

        if bounding_box is None:
            bounding_box = self.metadata['bounding_boxes'][0] 

        bbox = [float(p) for p in bounding_box]

        locations = eros.get_raster_availability(self.product_key, bbox)

        if os.path.exists(self.cache_file):
            existing = json.load(open(self.cache_file))
            locations = util.append_features(existing, locations)

        with open(self.cache_file, 'w') as f:
            dump(locations, f)

        return locations
github DigitalGlobe / mltools / mltools / geojson_tools.py View on Github external
input_files (list): List of file name strings.
           output_file (str): Output file name.
    '''

    # get feature collections
    final_features = []
    for file in input_files:
        with open(file) as f:
            feat_collection = geojson.load(f)
            final_features += feat_collection['features']

    feat_collection['features'] = final_features

    # write to output file
    with open(output_file, 'w') as f:
        geojson.dump(feat_collection, f)
github DigitalGlobe / mltools / polygon_pipeline.py View on Github external
# split feature lists into train and test
    if train_test:
        test_out = 'test_{}'.format(output_name + '.geojson')
        train_out = 'train_{}'.format(output_name + '.geojson')
        test_size = int(train_test * len(final))
        test = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final[:test_size]}
        train = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final[test_size:]}

        # save train and test geojsons
        with open(test_out, 'wb') as f1:
            geojson.dump(test, f1)
        print 'Test polygons saved as {}'.format(test_out)

        with open(train_out, 'wb') as f2:
            geojson.dump(train, f2)
        print 'Train polygons saved as {}'.format(train_out)

    else:  # only save one file with balanced classes
        balanced_json = {
            data.keys()[0]: data.values()[0],
            data.keys()[1]: final}
        with open(output_name + '.geojson', 'wb') as f:
            geojson.dump(balanced_json, f)
        print '{} polygons saved as {}.geojson'.format(len(final), output_name)
github DigitalGlobe / mltools / mltools / geojson_tools.py View on Github external
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)
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / outputters / weathering.py View on Github external
def output_to_file(self, json_content, step_num):
        file_format = 'mass_balance_{0:06d}.json'
        filename = os.path.join(self.output_dir,
                                file_format.format(step_num))

        with open(filename, 'w') as outfile:
            dump(json_content, outfile, indent=True)

        return filename
github mharnold / spiderosm / pnwk_network.py View on Github external
def write_geojson(self, name=None):
        if not name: name=self.name
        f = open(name+self.FILE_EXTENSION,'w')
        geojson.dump(self.__geo_interface__,f,indent=2,sort_keys=True)
        f.close()