Python shapely.geometry.polygon.LinearRing() Examples

The following are 3 code examples of shapely.geometry.polygon.LinearRing(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shapely.geometry.polygon , or try the search function .
Example #1
Source File: class4.py    From Ocean-Data-Map-Project with GNU General Public License v3.0 5 votes vote down vote up
def get_view_from_extent(extent):
    extent = list(map(float, extent.split(",")))
    view = LinearRing([
        (extent[1], extent[0]),
        (extent[3], extent[0]),
        (extent[3], extent[2]),
        (extent[1], extent[2])
    ])
    return view 
Example #2
Source File: misc.py    From Ocean-Data-Map-Project with GNU General Public License v3.0 5 votes vote down vote up
def _get_view(extent):
    extent = list(map(float, extent.split(",")))
    view = LinearRing([
        (extent[1], extent[0]),
        (extent[3], extent[0]),
        (extent[3], extent[2]),
        (extent[1], extent[2])
    ])
    return view 
Example #3
Source File: misc.py    From Ocean-Data-Map-Project with GNU General Public License v3.0 4 votes vote down vote up
def list_areas(file_id, simplify=True):
    AREA_DIR = os.path.join(current_app.config['OVERLAY_KML_DIR'], 'area')

    areas = []
    f = os.path.join(AREA_DIR, "%s.kml" % file_id)
    folder = ET.parse(f).getroot()
    nsmap = folder.tag.split("}", 1)[0] + "}"

    def get_coords(path):
        result = []
        for bound in place.iter(nsmap + path):
            for c in bound.iter(nsmap + "coordinates"):
                tuples = c.text.split(' ')
                coords = []
                for tup in tuples:
                    tup = tup.strip()
                    if not tup:
                        continue
                    lonlat = tup.split(',')
                    coords.append([float(lonlat[1]), float(lonlat[0])])

                if simplify:
                    coords = list(LinearRing(coords).simplify(1.0 / 32).coords)

                result.append(coords)

        return result

    for place in folder.iter(nsmap + "Placemark"):
        outers = get_coords("outerBoundaryIs")
        inners = get_coords("innerBoundaryIs")

        name = None
        for placename in place.iter(nsmap + "name"):
            name = placename.text
        centroids = [LinearRing(x).centroid for x in outers]
        areas.append({
            'name': name,
            'polygons': outers,
            'innerrings': inners,
            'centroids': [(c.y, c.x) for c in centroids],
            'key': file_id + "/" + name,
        })

    areas = sorted(areas, key=lambda k: k['name'])

    return areas