How to use the ogr.wkbLineString function in ogr

To help you get started, we’ve selected a few ogr 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 qgiscloud / qgis-cloud-plugin / qgiscloud / pyogr / ogr2ogr.py View on Github external
poDstLayer = None

#/* -------------------------------------------------------------------- */
#/*      If the layer does not exist, then create it.                    */
#/* -------------------------------------------------------------------- */
    if poDstLayer is None:
        if eGType == -2:
            eGType = poSrcFDefn.GetGeomType()

            if bExplodeCollections:
                n25DBit = eGType & ogr.wkb25DBit
                if wkbFlatten(eGType) == ogr.wkbMultiPoint:
                    eGType = ogr.wkbPoint | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbMultiLineString:
                    eGType = ogr.wkbLineString | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbMultiPolygon:
                    eGType = ogr.wkbPolygon | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbGeometryCollection:
                    eGType = ogr.wkbUnknown | n25DBit

            if pszZField is not None:
                eGType = eGType | ogr.wkb25DBit

        if poDstDS.TestCapability(ogr.ODsCCreateLayer) == False:
            print("Layer " + pszNewLayerName + "not found, and CreateLayer not supported by driver.")
            return False

        gdal.ErrorReset()

        poDstLayer = poDstDS.CreateLayer(pszNewLayerName, poOutputSRS, \
                                            eGType, papszLCO)
github sourcepole / ogrtools / ogrtools / pyogr / ogr2ogr.py View on Github external
if poDstDS.DeleteLayer(iLayer) != 0:
            print("DeleteLayer() failed when overwrite requested.")
            return None

        poDstLayer = None

#/* -------------------------------------------------------------------- */
#/*      If the layer does not exist, then create it.                    */
#/* -------------------------------------------------------------------- */
    if poDstLayer is None:
        if eGType == -2:
            eGType = poSrcFDefn.GetGeomType()

            n25DBit = eGType & ogr.wkb25DBit
            if bPromoteToMulti:
                if wkbFlatten(eGType) == ogr.wkbLineString:
                    eGType = ogr.wkbMultiLineString | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbPolygon:
                    eGType = ogr.wkbMultiPolygon | n25DBit

            if bExplodeCollections:
                if wkbFlatten(eGType) == ogr.wkbMultiPoint:
                    eGType = ogr.wkbPoint | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbMultiLineString:
                    eGType = ogr.wkbLineString | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbMultiPolygon:
                    eGType = ogr.wkbPolygon | n25DBit
                elif wkbFlatten(eGType) == ogr.wkbGeometryCollection:
                    eGType = ogr.wkbUnknown | n25DBit

            if pszZField is not None:
                eGType = eGType | ogr.wkb25DBit
github GeoscienceAustralia / anuga_core / source / anuga / utilities / spatialInputUtil.py View on Github external
# Avoid modifying ptsIn
        pts=copy.copy(ptsIn)
    
        if appendFirstOnEnd is None:
            if(geometry_type=='polygon'):
                appendFirstOnEnd=True
            else:
                appendFirstOnEnd=False
    
        if appendFirstOnEnd:
            pts.append(pts[0])    
        
        if(geometry_type=='point'):
            data=ogr.Geometry(ogr.wkbMultiPoint)
        elif(geometry_type=='line'):
            data=ogr.Geometry(ogr.wkbLineString)
        elif(geometry_type=='polygon'):
            data=ogr.Geometry(ogr.wkbLinearRing)
        else:
            raise Exception, "Type must be either 'point' or 'line' or 'polygon'"
         
        for i in range(len(pts)):
            if(len(pts[i])==2):
                if(geometry_type=='point'):
                    newPt=ogr.Geometry(ogr.wkbPoint)
                    newPt.AddPoint(pts[i][0], pts[i][1]) 
                    data.AddGeometryDirectly(newPt)
                else:
                    data.AddPoint(pts[i][0], pts[i][1])
            elif(len(pts[i])==3):
                if(geometry_type=='point'):
                    newPt=ogr.Geometry(ogr.wkbPoint)
github ofringer / suntanspy / GIS / maptools.py View on Github external
def get_shape_type(obj):
        if isinstance(obj,geometry.Polygon):
            return ogr.wkbPolygon
        elif isinstance(obj,geometry.LineString):
            return ogr.wkbLineString
        elif isinstance(obj,geometry.Point):
            return ogr.wkbPoint
        else:
            raise Exeption, 'incompatible type: %s'%(type(obj))
github sourcepole / ogrtools / ogrtools / pyogr / ogrinfo.py View on Github external
def DumpReadableGeometry(poGeometry, pszPrefix, options):

    if pszPrefix == None:
        pszPrefix = ""

    if 'DISPLAY_GEOMETRY' in options and EQUAL(options['DISPLAY_GEOMETRY'], 'SUMMARY'):

        line = ("%s%s : " % (pszPrefix, poGeometry.GetGeometryName()))
        eType = poGeometry.GetGeometryType()
        if eType == ogr.wkbLineString or eType == ogr.wkbLineString25D:
            line = line + ("%d points" % poGeometry.GetPointCount())
            print(line)
        elif eType == ogr.wkbPolygon or eType == ogr.wkbPolygon25D:
            nRings = poGeometry.GetGeometryCount()
            if nRings == 0:
                line = line + "empty"
            else:
                poRing = poGeometry.GetGeometryRef(0)
                line = line + ("%d points" % poRing.GetPointCount())
                if nRings > 1:
                    line = line + (", %d inner rings (" % (nRings - 1))
                    for ir in range(0, nRings - 1):
                        if ir > 0:
                            line = line + ", "
                        poRing = poGeometry.GetGeometryRef(ir + 1)
                        line = line + ("%d points" % poRing.GetPointCount())
github qgiscloud / qgis-cloud-plugin / qgiscloud / pyogr / ogr2ogr.py View on Github external
pszSQLStatement = args[iArg]

        elif EQUAL(args[iArg], "-nln") and iArg < nArgc - 1:
            iArg = iArg + 1
            pszNewLayerName = args[iArg]

        elif EQUAL(args[iArg], "-nlt") and iArg < nArgc - 1:

            if EQUAL(args[iArg + 1], "NONE"):
                eGType = ogr.wkbNone
            elif EQUAL(args[iArg + 1], "GEOMETRY"):
                eGType = ogr.wkbUnknown
            elif EQUAL(args[iArg + 1], "POINT"):
                eGType = ogr.wkbPoint
            elif EQUAL(args[iArg + 1], "LINESTRING"):
                eGType = ogr.wkbLineString
            elif EQUAL(args[iArg + 1], "POLYGON"):
                eGType = ogr.wkbPolygon
            elif EQUAL(args[iArg + 1], "GEOMETRYCOLLECTION"):
                eGType = ogr.wkbGeometryCollection
            elif EQUAL(args[iArg + 1], "MULTIPOINT"):
                eGType = ogr.wkbMultiPoint
            elif EQUAL(args[iArg + 1], "MULTILINESTRING"):
                eGType = ogr.wkbMultiLineString
            elif EQUAL(args[iArg + 1], "MULTIPOLYGON"):
                eGType = ogr.wkbMultiPolygon
            elif EQUAL(args[iArg + 1], "GEOMETRY25D"):
                eGType = ogr.wkbUnknown | ogr.wkb25DBit
            elif EQUAL(args[iArg + 1], "POINT25D"):
                eGType = ogr.wkbPoint25D
            elif EQUAL(args[iArg + 1], "LINESTRING25D"):
                eGType = ogr.wkbLineString25D
github mapmint / mapmint / mapmint-services / vector-tools-src / cgi-env / vectSql.py View on Github external
def DumpReadableGeometry( poGeometry, pszPrefix, options ):

    if pszPrefix == None:
        pszPrefix = ""

    if 'DISPLAY_GEOMETRY' in options and EQUAL(options['DISPLAY_GEOMETRY'], 'SUMMARY'):

        line = ("%s%s : " % (pszPrefix, poGeometry.GetGeometryName() ))
        eType = poGeometry.GetGeometryType()
        if eType == ogr.wkbLineString or eType == ogr.wkbLineString25D:
            line = line + ("%d points" % poGeometry.GetPointCount())
            print(line)
        elif eType == ogr.wkbPolygon or eType == ogr.wkbPolygon25D:
            nRings = poGeometry.GetGeometryCount()
            if nRings == 0:
                line = line + "empty"
            else:
                poRing = poGeometry.GetGeometryRef(0)
                line = line + ("%d points" % poRing.GetPointCount())
                if nRings > 1:
                    line = line + (", %d inner rings (" % (nRings - 1))
                    for ir in range(0,nRings-1):
                        if ir > 0:
                            line = line + ", "
                        poRing = poGeometry.GetGeometryRef(ir+1)
                        line = line + ("%d points" % poRing.GetPointCount())
github iocast / featureserver / FeatureServer / VectorFormats / Formats / OGR.py View on Github external
if gtype == ogr.wkbPolygon or gtype == ogr.wkbPolygon25D:
                geom = geometry.GetGeometryRef(0)
                coordinates = get_coordinates(geom)
                return [coordinates]
    
            if gtype == ogr.wkbMultiPolygon or gtype == ogr.wkbMultiPolygon25D:
    
                coordinates = []
                geom_count = geometry.GetGeometryCount()
                for g in range(geom_count):
                    geom = geometry.GetGeometryRef(g)
                    coordinates.append(get_coordinates(geom))
                return coordinates
                
        types = { ogr.wkbPoint:'Point',
                  ogr.wkbLineString: 'LineString',
                  ogr.wkbPolygon: 'Polygon',
                  ogr.wkbMultiPoint: 'MultiPoint',
                  ogr.wkbMultiLineString: 'MultiLineString',
                  ogr.wkbMultiPolygon: 'MultiPolygon',
                  ogr.wkbGeometryCollection: 'GeometryCollection'  
        }
    
        output = {'type': types[geometry.GetGeometryType()],
                  'coordinates': get_coordinates(geometry)}
        return output
github iocast / featureserver / FeatureServer / DataSource / OGR.py View on Github external
from VectorFormats.Feature import Feature

try:
    from osgeo import ogr
    from osgeo import osr
except:
    import ogr
    import osr

class OGR (DataSource):
    """Uses the ogr Python bindings to query/update/delete an OGR 
       datasource. Feature support is limited in the same way as 
       OGR's underlying datasource.""" 
    freeze_type = {
        ogr.wkbPoint            : "Point",
        ogr.wkbLineString       : "LineString",
        ogr.wkbPolygon          : "Polygon",
        ogr.wkbMultiPoint       : "Point",
        ogr.wkbMultiLineString  : "LineString",
        ogr.wkbMultiPolygon     : "Polygon"
    }
    # thaw_type = dict(map(lambda (x,y): (y,x), freeze_type.items()))
    thaw_type = {
        "Point"     : ogr.wkbPoint,
        "LineString": ogr.wkbLineString,
        "Polygon"   : ogr.wkbPolygon
    }
    error_msgs = [
        "OK",
        "Not enough data",
        "Not enough memory",
        "Unsupported geometry type",