Example #1
0
def loadShapefile(file_name):
    global db
    # shp_bounding_box = []
    # shp_type = 0
    file_name = file_name
    records = []
    # open dbf file and get records as a list
    dbf_file = file_name[0:-4] + '.dbf'
    dbf = open(dbf_file, 'rb')
    db = list(dbfutils.dbfreader(dbf))
    dbf.close()
    fp = open(file_name, 'rb')

    # get basic shapefile configuration
    fp.seek(32)
    # shp_type = readAndUnpack('i', fp.read(4))
    readAndUnpack('i', fp.read(4))
    # shp_bounding_box = readBoundingBox(fp)
    readBoundingBox(fp)

    # fetch Records
    fp.seek(100)
    while True:
        shp_record = createRecord(fp)
        if shp_record is False:
            break
        records.append(shp_record)

    return records
Example #2
0
def load_shapefile(file_name):
    global db
    file_name = file_name
    records = []
    # open dbf file and get records as a list
    dbf_file = file_name[0:-4] + ".dbf"
    dbf = open(dbf_file, "rb")
    db = list(dbfutils.dbfreader(dbf))
    dbf.close()
    fp = open(file_name, "rb")

    # get basic shapefile configuration
    fp.seek(32)
    read_and_unpack("i", fp.read(4))
    read_bounding_box(fp)

    # fetch Records
    fp.seek(100)
    while True:
        shp_record = create_record(fp)
        if not shp_record:
            break
        records.append(shp_record)

    return records
Example #3
0
def loadShapefile(file_name):
    global db
    shp_bounding_box = []
    shp_type = 0
    file_name = file_name
    records = []
    # open dbf file and get records as a list
    dbf_file = file_name[0:-4] + '.dbf'
    dbf = open(dbf_file, 'rb')
    db = list(dbfutils.dbfreader(dbf))
    dbf.close()
    fp = open(file_name, 'rb')

    # get basic shapefile configuration
    fp.seek(32)
    shp_type = readAndUnpack('i', fp.read(4))
    shp_bounding_box = readBoundingBox(fp)

    # fetch Records
    fp.seek(100)
    while True:
        shp_record = createRecord(fp)
        if shp_record == False:
            break
        records.append(shp_record)

    return records
Example #4
0
    def parse(self):
        # Get basic shapefile configuration.
        fp = open(self.__filename, 'rb')

        if self._readAndUnpack(self.__BE_SINT, fp.read(4)) != 9994:
            raise ValueError("Invalid or corrupted shapefile.")

        # Open dbf file and get features as a list.
        dbfile = open(self.__filename[0:-4] + '.dbf', 'rb')
        self.__db[:] = list(dbfutils.dbfreader(dbfile))
        dbfile.close()

        fp.seek(32)
        shapeType = self._readAndUnpack(self.__LE_SINT, fp.read(4))
        self.__shapeType = shapeType
        # Get surface bounds.
        bounds = self._readBounds(fp)
        # Get Z (axis) and M (measure) bounds if any.
        bounds += self._readBounds(fp)

        # Fetch Records.
        features = []

        while True:
            feature = self._createRecord(fp, shapeType)
            if not feature: break

            if shapeType in (self._POLYLINE, self._POLYGON,
                             self._POLYLINE_Z, self._POLYGON_Z,
                             self._POLYLINE_M, self._POLYGON_M):
                self._processPolyInfo(feature)

            features.append(feature)

        return {'type': shapeType, 'bounds': bounds, 'features': features}