コード例 #1
0
ファイル: shapefile_to_kml.py プロジェクト: just4jin/pygis
    def to_kml( self ):

        """
        Summary:  This method opens an ESRI shapefile and extracts all the
        vertices for every feature (point, polygon), attribute table data names and
        attribure table row data.  All this data is packaged in a bundle (a
        list) and passed to a generate kml method.  The method automatically
        detects the geometry type (point or polygon) and passes it to the
        proper 'make kml' method.

        """

        # calls a method in shapefile_utilities that grabs the shapefile's
        # coordinates, attribute columns, attribute row data and other information.
        kmlPacket = get_shapefile_data( self.shapeFilePath )

        self.kmlBundle = kmlPacket[0] 
        self.attributeColumns = kmlPacket[1] 
        self.coordHolder = kmlPacket[2] 
        self.geomTracker = kmlPacket[3] 
        self.fileRoot = kmlPacket[4]
        
        # calls method from pygis.kml.kml_utilities. The kwarg 'fromShapefile' HAS to be set to 'True'.
        make_kml( 
                 self.outFolderPath, 
                 self.fileRoot + '.kml',    # kmlFileName 
                 self.kmlBundle[1:],        # bubbleFields 
                 self.geomTracker,          # bundle of data 
                 self.kmlBundle[0],
                 fromShapefile=True
                )
コード例 #2
0
ファイル: shapefile_to_kml.py プロジェクト: sunnycd/pygis
    def to_kml(self):
        """
        Summary:  This method opens an ESRI shapefile and extracts all the
        vertices for every feature (point, polygon), attribute table data names and
        attribure table row data.  All this data is packaged in a bundle (a
        list) and passed to a generate kml method.  The method automatically
        detects the geometry type (point or polygon) and passes it to the
        proper 'make kml' method.

        """

        # calls a method in shapefile_utilities that grabs the shapefile's
        # coordinates, attribute columns, attribute row data and other information.
        kmlPacket = get_shapefile_data(self.shapeFilePath)

        self.kmlBundle = kmlPacket[0]
        self.attributeColumns = kmlPacket[1]
        self.coordHolder = kmlPacket[2]
        self.geomTracker = kmlPacket[3]
        self.fileRoot = kmlPacket[4]

        # calls method from pygis.kml.kml_utilities. The kwarg 'fromShapefile' HAS to be set to 'True'.
        make_kml(
            self.outFolderPath,
            self.fileRoot + '.kml',  # kmlFileName 
            self.kmlBundle[1:],  # bubbleFields 
            self.geomTracker,  # bundle of data 
            self.kmlBundle[0],
            fromShapefile=True)
コード例 #3
0
ファイル: get_shapefile_data.py プロジェクト: just4jin/pygis
    def get( self ):

        """
        This method pass the shapefilepath to a method in a module that returns
        all the needed data.  It uses the returned data to parse it
        appropriately for the geometery type (i.e point or polygon)

        """

        # the 'get_shapefile_data() method is called from the
        # 'shapefile_utilities' module. The returned data is assigned to a variable
        kmlPacket = get_shapefile_data( self.shapeFilePath )

        #  The packet of data is taken apart and the appropriate variables are assigned
        self.kmlBundle = kmlPacket[0] 
        self.attributeColumns = kmlPacket[1] 
        self.geomType = kmlPacket[3] 
        self.fileName = kmlPacket[4] + '.shp'
        self.vertices = []
        self.featureCount = ''
        self.attributeRowData = []
        coordHolder = kmlPacket[2]

        # Assigned proper attributes for point shapefiles
        if self.geomType == 'Point':
        
            self.vertices = [ x[:2] for x in coordHolder ]

            self.featureCount =  len( self.vertices )

            self.attributeRowData = [ x[2:] for x in coordHolder ]

            
        # Assigned proper attributes for polygon shapefiles
        elif self.geomType == 'Polygon':

            self.vertices = [ x[:-1] for x in coordHolder ]

            self.featureCount =  len( self.vertices )

            self.attributeRowData = [ x[-1:][0] for x in coordHolder ]

        # Exit if something didn't work or if the geometry type is a polyline, which isn't supported.
        else:

            print 'Something happend and there is an unexpected failure'
            sys.exit(1)
コード例 #4
0
    def get(self):
        """
        This method pass the shapefilepath to a method in a module that returns
        all the needed data.  It uses the returned data to parse it
        appropriately for the geometery type (i.e point or polygon)

        """

        # the 'get_shapefile_data() method is called from the
        # 'shapefile_utilities' module. The returned data is assigned to a variable
        kmlPacket = get_shapefile_data(self.shapeFilePath)

        #  The packet of data is taken apart and the appropriate variables are assigned
        self.kmlBundle = kmlPacket[0]
        self.attributeColumns = kmlPacket[1]
        self.geomType = kmlPacket[3]
        self.fileName = kmlPacket[4] + '.shp'
        self.vertices = []
        self.featureCount = ''
        self.attributeRowData = []
        coordHolder = kmlPacket[2]

        # Assigned proper attributes for point shapefiles
        if self.geomType == 'Point':

            self.vertices = [x[:2] for x in coordHolder]

            self.featureCount = len(self.vertices)

            self.attributeRowData = [x[2:] for x in coordHolder]

        # Assigned proper attributes for polygon shapefiles
        elif self.geomType == 'Polygon':

            self.vertices = [x[:-1] for x in coordHolder]

            self.featureCount = len(self.vertices)

            self.attributeRowData = [x[-1:][0] for x in coordHolder]

        # Exit if something didn't work or if the geometry type is a polyline, which isn't supported.
        else:

            print 'Something happend and there is an unexpected failure'
            sys.exit(1)