How to use the shapely.wkt.loads function in shapely

To help you get started, we’ve selected a few shapely 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 tilezen / vector-datasource / integration-test / 742-predictable-layers-pois.py View on Github external
def test_natural_forest_way(self):
        # Way: natural: Forest in POIS
        # note: since #1103, there should be no POIs for natural_forest,
        # only label placements in the landuse layer.
        self.generate_fixtures(dsl.way(202680509, wkt_loads('POLYGON ((-72.8282241701547 41.55614730899158, -72.82812769109321 41.55637606326199, -72.8279667129943 41.55658491930441, -72.82781651467879 41.5568056727527, -72.8276770961467 41.55695819654311, -72.8274087693713 41.5571548838084, -72.82728013062258 41.5572231125046, -72.82711385246348 41.55733550484018, -72.82694748447291 41.55735956968099, -72.82680267604908 41.55735956968099, -72.8266793373606 41.5572752754789, -72.82659336858789 41.55715091780307, -72.8265880685277 41.5569942940115, -72.82660953826299 41.55681367202608, -72.8267328769515 41.55660091790489, -72.82680267604908 41.55641229549799, -72.82690463483389 41.55614327570299, -72.8269947358569 41.5559353593372, -72.8272747407309 41.55583015730019, -72.8275161180478 41.55573389560568, -72.82773072556908 41.55566956421178, -72.82791847346348 41.55568569748268, -72.82811691130981 41.55577395984789, -72.82818132051568 41.55586228931429, -72.82820198176718 41.55594261927978, -72.82820809031109 41.5560308812941, -72.8282241701547 41.55614730899158))'), {u'natural': u'forest', u'name': u'Mine Island', u'way_area': u'29390.7', u'ele': u'134', u'source': u'openstreetmap.org', u'place': u'island'}))  # noqa

        self.assert_no_matching_feature(
            14, 4877, 6109, 'pois',
            {'id': 202680509, 'kind': 'natural_forest'})

        # Label placement forest in landuse
        self.assert_has_feature(
            15, 9755, 12218, 'landuse',
            {'id': 202680509, 'kind': 'natural_forest',
             'label_placement': True})
github tilezen / vector-datasource / integration-test / 1218-poni-whitelist.py View on Github external
def test_aeroway_helipad(self):
        # aeroway=helipad
        # min_zoom: 16
        self.generate_fixtures(dsl.way(2207370738, wkt_loads('POINT (-122.532516658118 37.84209588684551)'), {u'source': u'openstreetmap.org', u'aeroway': u'helipad'}))  # noqa

        self.assert_no_matching_feature(
            15, 5230, 12657, 'pois',
            {'id': 2207370738})

        self.assert_has_feature(
            16, 10461, 25315, 'pois',
            {'id': 2207370738})
github tilezen / vector-datasource / integration-test / 1218-poni-whitelist.py View on Github external
def test_railway_platform(self):
        self.generate_fixtures(dsl.way(3987143106, wkt_loads('POINT (-72.0929836528225 41.354925008914)'), {u'source': u'openstreetmap.org', u'railway': u'platform'}))  # noqa

        self.assert_has_feature(
            16, 19643, 24485, 'pois',
            {'id': 3987143106, 'min_zoom': 17})
github NCPP / ocgis / ocgis_merge / src / openclimategis / util / ncconv / experimental / tests.py View on Github external
def usa(self,check_extent=True,check_masked=True):
        if verbose: print('getting usa features...')
        itr = ShpIterator(self.shp_path)
        ocg_dataset = self.ocg_dataset
        polygons = []
        for feat in itr.iter_features(['STATE_ABBR']):
            geom = wkt.loads(feat['geom'])
            if not isinstance(geom,Polygon):
                for poly in geom:
                    polygons.append(poly)
            else:
                polygons.append(geom)
        if check_extent:
            if verbose: print('  checking extent...')
            polygons = filter(ocg_dataset.check_extent,polygons)
        if check_masked:
            if verbose: print('  checking masked...')
            keep = []
            for poly in polygons:
                if ocg_dataset.check_masked(self.nc_var_name,poly):
                    keep.append(poly)
            polygons = keep
        if verbose: print('  done.')
github camptocamp / tilecloud / tilecloud / store / geometry.py View on Github external
bounds = {}
        for zoom in range(0, len(self.metatile_configuration.resolutions)):
            x_bounds = Bounds(self.unit_to_metatile(bbox[0], zoom, self.metatile_configuration.max_extent[0]),
                self.unit_to_metatile(bbox[2], zoom, self.metatile_configuration.max_extent[0]) + 1)
            y_bounds = Bounds(self.unit_to_metatile(bbox[1], zoom, self.metatile_configuration.max_extent[1]),
                self.unit_to_metatile(bbox[3], zoom, self.metatile_configuration.max_extent[1]) + 1)
            bounds[zoom] = (x_bounds, y_bounds)

        bounding_pyramid = BoundingPyramid(bounds)
        for tilecoord in bounding_pyramid:
            zoom, meta_x, meta_y = tilecoord.z, tilecoord.x, tilecoord.y
            for x in range(meta_x * self.metatile_configuration.size,
                    meta_x * self.metatile_configuration.size + self.metatile_configuration.size):
                for y in range(meta_y * self.metatile_configuration.size,
                        meta_y * self.metatile_configuration.size + self.metatile_configuration.size):
                    extent = loads_wkt(self.polygon((
                            self.tile_to_unit(x, zoom, self.metatile_configuration.max_extent[0]),
                            self.tile_to_unit(y, zoom, self.metatile_configuration.max_extent[1]),
                            self.tile_to_unit(x + 1, zoom, self.metatile_configuration.max_extent[0]),
                            self.tile_to_unit(y + 1, zoom, self.metatile_configuration.max_extent[1])
                    )))
                    tile = Tile(TileCoord(zoom, x, y), meta=tilecoord)
                    if extent.intersects(self.geom):
                        yield self.get_one(tile)
github mapbox / wikimama / match.py View on Github external
count = 0
final = []

for osm_l in reader_osm:
    count += 1
    wiki_arr = []
    choices = []
    mapping = {}
    if osm_l['wikidata'] == "":
        scored = []
        reader_wiki = csvReader(input_wiki)
        for wiki_l in reader_wiki:
            place_label = wiki_l['place_label']
            location = wiki_l['location']
            try:
                pt = shapely.wkt.loads(location)
                gt = geojson.Feature(geometry=pt, properties={})
                wiki_geojson = shapely.geometry.shape(gt.geometry)
                distance = vincenty((osm_l['lon'], osm_l['lat']),(wiki_geojson.centroid.x, wiki_geojson.centroid.y)).km
                wiki_l["distance"] = distance
            except:
                wiki_l["distance"] = 1000
            if distance <= threshold:
                wiki_arr.append(wiki_l)
                choices.append(place_label)
                if place_label in mapping:
                    mapping[place_label].append(wiki_l)
                else:
                    mapping[place_label] = []
                    mapping[place_label].append(wiki_l)
        name = ""
        if 'name:en' in osm_l and osm_l['name:en'] != "":
github hotosm / tasking-manager / osmtm / utils.py View on Github external
def convert_to_multipolygon(features):
    from shapely.geometry import MultiPolygon

    rings = []
    for feature in features:
        if isinstance(feature.geometry, MultiPolygon):
            rings = rings + [geom for geom in feature.geometry.geoms]
        else:
            rings = rings + [feature.geometry]

    geometry = MultiPolygon(rings)

    # Downsample 3D -> 2D
    wkt2d = geometry.to_wkt()
    geom2d = shapely.wkt.loads(wkt2d)

    return geom2d
github nismod / digital_comms / scripts / network_preprocess_simplify_inputs.py View on Github external
def premises():
        i = 0
        for lad in lads:
            directory = os.path.join(DATA_BUILDING_DATA, 'prems_by_lad', lad)
            pathlist = glob.iglob(directory + '/*.csv', recursive=True)
            for path in pathlist:
                with open(path, 'r') as system_file:
                    reader = csv.DictReader(system_file)
                    next(reader)
                    for line in reader:
                        geom = loads(line['geom'])
                        geom_point = geom.representative_point()
                        feature = {
                            'type': 'Feature',
                            'geometry': mapping(geom),
                            'representative_point': geom_point,
                            'properties':{
                                #'landparcel_id': line[0],
                                #'mistral_function': line[1],
                                'toid': line['toid'],
                                #'household_id': line[4],
                                #'res_count': line[6],
                                #'lad': line[13],
                                'oa': line['oa'],
                            }
                        }
                        yield (i, geom_point.bounds, feature)
github Applied-GeoSolutions / lidar2dems / lidar2dems / scripts / process_photos.py View on Github external
def geotag(files, shapefile, attr, epsg='4326', res=0.5, outdir=''):
    """ Geotag all these files using the given attribute in the shapefile """
    outdir = os.path.abspath(outdir)
    mkdir(outdir)
    shp = gippy.GeoVector(shapefile)
    geoms = {}
    # cycle through features and load them up
    attrs = shp.Attributes()
    if attr not in attrs:
        print 'LINK'
        attr = 'LINK'

    for f in shp:
        fname = ntbasename(f[attr])
        geoms[fname] = loads(f.WKT()).exterior.coords[:]

    for fname in files:
        bname = os.path.basename(fname)
        if bname in geoms.keys():
            coords = geoms[bname]

            try:
                # add gcps and set projection
                img = gippy.GeoImage(fname, True)
            except:
                print 'Error reading %s' % fname
                continue
            x = [c[0] for c in coords]
            y = [c[1] for c in coords]
            gcps = numpy.array([
                [0, 0, x[1], y[1]],
github lopuhin / kaggle-dstl / utils.py View on Github external
def load_polygons(im_id: str, im_size: Tuple[int, int])\
        -> Dict[int, MultiPolygon]:
    return {
        int(poly_type): scale_to_mask(im_id, im_size, shapely.wkt.loads(poly))
        for poly_type, poly in get_wkt_data()[im_id].items()}