parameters: (shapeSrc, outputFileName, polyToCut)
docstring: docstring for clipShapeFile
docstring_summary: docstring for clipShapeFile
docstring_tokens: docstring for clipShapeFile
function: def clipShapeFile(shapeSrc, outputFileName, polyToCut):
      """docstring for clipShapeFile"""
  
      source_layer = shapeSrc.GetLayer()
      source_srs = source_layer.GetSpatialRef()
      # Create the output Layer
      outGeoJSon = outputFileName.replace('.tif', '.geojson')
      outDriver = ogr.GetDriverByName("geojson")
      if os.path.exists(outGeoJSon):
          outDriver.DeleteDataSource(outGeoJSon)
  
      outDataSource = outDriver.CreateDataSource(outGeoJSon)
      outLayer = outDataSource.CreateLayer("groundTruth", source_srs, geom_type=ogr.wkbPolygon)
      # Add input Layer Fields to the output Layer
      inLayerDefn = source_layer.GetLayerDefn()
      for i in range(0, inLayerDefn.GetFieldCount()):
          fieldDefn = inLayerDefn.GetFieldDefn(i)
          outLayer.CreateField(fieldDefn)
      outLayer.CreateField(ogr.FieldDefn("partialBuilding", ogr.OFTInteger))
      outLayerDefn = outLayer.GetLayerDefn()
      source_layer.SetSpatialFilter(polyToCut)
      for inFeature in source_layer:
  
          outFeature = ogr.Feature(outLayerDefn)
  
          for i in range(0, inLayerDefn.GetFieldCount()):
              outFeature.SetField(inLayerDefn.GetFieldDefn(i).GetNameRef(), inFeature.GetField(i))
  
          geom = inFeature.GetGeometryRef()
          geomNew = geom.Intersection(polyToCut)
          if geomNew:
              if geom.GetArea() == geomNew.GetArea():
                  outFeature.SetField("partialBuilding", 0)
              else:
                  outFeature.SetField("partialBuilding", 1)
          else:
              outFeature.SetField("partialBuilding", 1)
  
  
          outFeature.SetGeometry(geomNew)
          outLayer.CreateFeature(outFeature)
function_tokens: def clipShapeFile ( shapeSrc , outputFileName , polyToCut ) : source_layer = shapeSrc . GetLayer ( ) source_srs = source_layer . GetSpatialRef ( ) # Create the output Layer outGeoJSon = outputFileName . replace ( '.tif' , '.geojson' ) outDriver = ogr . GetDriverByName ( "geojson" ) if os . path . exists ( outGeoJSon ) : outDriver . DeleteDataSource ( outGeoJSon ) outDataSource = outDriver . CreateDataSource ( outGeoJSon ) outLayer = outDataSource . CreateLayer ( "groundTruth" , source_srs , geom_type = ogr . wkbPolygon ) # Add input Layer Fields to the output Layer inLayerDefn = source_layer . GetLayerDefn ( ) for i in range ( 0 , inLayerDefn . GetFieldCount ( ) ) : fieldDefn = inLayerDefn . GetFieldDefn ( i ) outLayer . CreateField ( fieldDefn ) outLayer . CreateField ( ogr . FieldDefn ( "partialBuilding" , ogr . OFTInteger ) ) outLayerDefn = outLayer . GetLayerDefn ( ) source_layer . SetSpatialFilter ( polyToCut ) for inFeature in source_layer : outFeature = ogr . Feature ( outLayerDefn ) for i in range ( 0 , inLayerDefn . GetFieldCount ( ) ) : outFeature . SetField ( inLayerDefn . GetFieldDefn ( i ) . GetNameRef ( ) , inFeature . GetField ( i ) ) geom = inFeature . GetGeometryRef ( ) geomNew = geom . Intersection ( polyToCut ) if geomNew : if geom . GetArea ( ) == geomNew . GetArea ( ) : outFeature . SetField ( "partialBuilding" , 0 ) else : outFeature . SetField ( "partialBuilding" , 1 ) else : outFeature . SetField ( "partialBuilding" , 1 ) outFeature . SetGeometry ( geomNew ) outLayer . CreateFeature ( outFeature )