How to use the geojson.MultiLineString 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_constructor.py View on Github external
def test_nested_constructors(self):
        a = [5, 6]
        b = [9, 10]
        c = [-5, 12]
        mp = geojson.MultiPoint([geojson.Point(a), b])
        self.assertEquals(mp.coordinates, [a, b])

        mls = geojson.MultiLineString([geojson.LineString([a, b]), [a, c]])
        self.assertEquals(mls.coordinates, [[a, b], [a, c]])

        outer = [a, b, c, a]
        poly = geojson.Polygon(geojson.MultiPoint(outer))
        other = [[1, 1], [1, 2], [2, 1], [1, 1]]
        poly2 = geojson.Polygon([outer, other])
        self.assertEquals(geojson.MultiPolygon([poly, poly2]).coordinates,
                          [[outer], [outer, other]])
github jazzband / geojson / tests / test_validation.py View on Github external
def test_valid_multilinestring(self):
        ls1 = [(3.75, 9.25), (-130.95, 1.52)]
        ls2 = [(23.15, -34.25), (-1.35, -4.65), (3.45, 77.95)]
        mls = geojson.MultiLineString([ls1, ls2])
        self.assertEqual(mls.is_valid, True)
github jazzband / geojson / tests / test_validation.py View on Github external
def test_invalid_multilinestring(self):
        with self.assertRaises(ValueError) as cm:
            geojson.MultiLineString([1], validate=True)

        self.assertIn('each line must be a list of positions',
                      str(cm.exception))

        mls = geojson.MultiLineString([[(10, 5), (20, 1)], []])
        self.assertEqual(mls.is_valid, False)
github jazzband / geojson / geojson / validation.py View on Github external
if isinstance(obj, geojson.Point):
        if len(obj['coordinates']) not in (2, 3):
            return output('the "coordinates" member must be a single position')

    if isinstance(obj, geojson.MultiPoint):
        if checkListOfObjects(obj['coordinates'], lambda x: len(x) in (2, 3)):
            return output(
                'the "coordinates" member must be an array of positions'
            )

    if isinstance(obj, geojson.LineString):
        if len(obj['coordinates']) < 2:
            return output('the "coordinates" member must be an array '
                          'of two or more positions')

    if isinstance(obj, geojson.MultiLineString):
        coord = obj['coordinates']
        if checkListOfObjects(coord, lambda x: len(x) >= 2):
            return output('the "coordinates" member must be an array '
                          'of LineString coordinate arrays')

    if isinstance(obj, geojson.Polygon):
        coord = obj['coordinates']
        lengths = all([len(elem) >= 4 for elem in coord])
        if lengths is False:
            return output('LinearRing must contain with 4 or more positions')

        isring = all([elem[0] == elem[-1] for elem in coord])
        if isring is False:
            return output('The first and last positions in LinearRing'
                          'must be equivalent')
github vipyoung / kharita / methods_kharita.py View on Github external
def getgeojson(gedges,seeds):
    inp = []
    for xx in gedges:
        ll1 = seeds[xx[0]]; ll2 = seeds[xx[1]];
        inp.append([(ll1[0],ll1[1]),(ll2[0],ll2[1])])
    with open('map0.geojson', 'w') as fdist:
        fdist.write(MultiLineString(inp))
github ekansa / open-context-py / opencontext_py / apps / ocitems / ocitem / models.py View on Github external
'intentional reduction in precision.'
                    item_point = Point((float(geo.longitude), float(geo.latitude)))
                    item_f_point = Feature(geometry=item_point)
                    item_f_point.properties.update(geo_props)
                    if uuid == geo.uuid:
                        #the item itself has the polygon as it's feature
                        item_db = Point((float(geo.longitude), float(geo.latitude)))
                        if(geo.ftype == 'Polygon'):
                            coord_obj = json.loads(geo.coordinates)
                            item_db = Polygon(coord_obj)
                        elif(geo.ftype == 'MultiPolygon'):
                            coord_obj = json.loads(geo.coordinates)
                            item_db = MultiPolygon(coord_obj)
                        elif(geo.ftype == 'MultiLineString'):
                            coord_obj = json.loads(geo.coordinates)
                            item_db = MultiLineString(coord_obj)
                        item_f_db = Feature(geometry=item_db)
                        item_f_db.id = geo_node
                        item_f_db.geometry.id = geo_node_geom
                        item_f_db.properties.update(geo_props)
                        item_f_db.properties['id'] = geo_node_props
                        features_dict[geo_node] = item_f_db
                        item_f_point.id = geo_node_derived
                        item_f_point.geometry.id = geo_node_derived_geom
                        item_f_point.properties['location-region-note'] = 'This point represents the center of the '\
                                                                          'region defining the location of this item.'
                        item_f_point.properties['id'] = geo_node_derived_props
                        features_dict[geo_node_derived] = item_f_point
                    else:
                        #the item is contained within another item with a polygon or multipolygon feature
                        item_f_point.id = geo_node
                        item_f_point.geometry.id = geo_node_geom
github krischer / LASIF / lasif / webinterface / server.py View on Github external
def get_domain_geojson():
    """
    Return the domain as GeoJSON multipath.
    """
    domain = app.comm.project.domain

    outer_border = domain.border
    inner_border = domain.inner_border

    border = geojson.MultiLineString([
        [(_i[1], _i[0]) for _i in inner_border],
        [(_i[1], _i[0]) for _i in outer_border],
    ])
    return flask.jsonify(**border)
github geoadmin / mf-chsdi3 / chsdi / esrigeojsonencoder.py View on Github external
ret['paths'] = [[xy for xy in path]]
                ret['type'] = 'esriGeometryPolyline'
                ret = self._hasZ(xy, ret)

                return self._cleanup(ret)

            if isinstance(obj, (geojson.MultiPoint)):
                ret = dict(obj)
                points = [xy for xy in coordinates]
                ret['points'] = points
                ret['type'] = 'esriGeometryMultipoint'
                ret = self._hasZ(xy, ret)

                return self._cleanup(ret)

            if isinstance(obj, geojson.MultiLineString):
                ret = dict(obj)

                paths = coordinates
                ret['paths'] = [[xy for xy in p] for p in paths]
                ret['type'] = 'esriGeometryPolyline'
                ret = self._hasZ(xy, ret)

                return self._cleanup(ret)

            if isinstance(obj, (geojson.Polygon, geojson.geometry.Polygon)) or geom_type == 'Polygon':
                ret = dict(obj)

                rings = coordinates
                ret['rings'] = [[xy for xy in ring] for ring in rings]
                ret['type'] = 'esriGeometryPolygon'
                ret = self._hasZ(xy, ret)
github SuperMap / iclient-python / iclientpy / iclientpy / data / featuresconverter.py View on Github external
def from_geojson_feature(geo):
    s_feature = icp_model.Feature()
    s_feature.fieldNames = list(geo['properties'].keys())
    s_feature.fieldValues = list(geo['properties'].values())
    if type(geo['geometry']) in (geojson.Point, geojson.MultiPoint):
        s_feature.geometry = __from_geojson_point(geo['geometry'])
    elif type(geo['geometry']) in (geojson.LineString, geojson.MultiLineString):
        s_feature.geometry = __from_geojson_line(geo['geometry'])
    elif type(geo['geometry']) in (geojson.Polygon, geojson.MultiPolygon):
        s_feature.geometry = __from_geojson_polygon(geo['geometry'])
    return s_feature
github SEL-Columbia / networkplanner / np / lib / dataset_store.py View on Github external
def exportGeoJSONGeometry(self, transform_point=None):
        coordinates = self.getCommonCoordinates()
        if transform_point:
            coordinates = [(transform_point(*x[0]), transform_point(*x[1])) for x in coordinates]
        return geojson.MultiLineString(coordinates)