FileIO

Use Fiona to read points from a file and write the resulting polygon to a file.

Supported Drivers

drvdata = list()
for drv, modes in fiona.supported_drivers.items():
    drvdata.append([drv, modes])
drvdata.sort()

for i, item in enumerate(drvdata):
    drv = item[0]
    extlist = list()
    for extension in extensions(drv) or ():
        extlist.append(extension)
    extoptions = ''
    for j, extension in enumerate(extlist):
        extoptions += extension
        if j < len(extlist)-1:
            extoptions += ', '
    item.append(extoptions)
    item.insert(0, (str(i+1)+'.'))

columns = ['No', 'Driver', 'Modes', 'Extensions']
tabulate(drvdata, headers=columns, tablefmt='html')
#print(tabulate(drvdata, headers=columns))
No Driver Modes Extensions
1 CSV raw csv, tsv, psv
2 DGN raw dgn
3 DXF rw dxf
4 ESRI Shapefile raw shp, dbf, shz, shp.zip
5 ESRIJSON r json
6 FlatGeobuf raw fgb
7 GML rw gml, xml
8 GPKG raw gpkg, gpkg.zip
9 GPX rw gpx
10 GeoJSON raw json, geojson
11 GeoJSONSeq raw geojsonl, geojsons
12 Idrisi r vct
13 MapInfo File raw tab, mif, mid
14 OGR_GMT rw gmt
15 OGR_PDS r
16 OpenFileGDB raw gdb
17 PCIDSK raw pix
18 S57 r 000
19 SQLite raw sqlite, db
20 TopoJSON r json, topojson

source

FileIO

 FileIO ()

Calculate the concave hull of a collection of points.


source

FileIO.file2points

 FileIO.file2points (infile:str, inlayer:str=None)

Reads a file with a format supported by Fiona. Extracts all the points and add it to the point list.

Parameters:
    infile (str)  : The file name
    inlayer (str) : The layer in the file where applicable

Returns:
    None

Todo: Provide option to breakdown LineStrings and Polygon to points. Do I need to check for point duplication? Easy, but will require a new dependency, rtree.

   def file2points(self, infile:str, inlayer: str=None, 
                   allgeometries: bool=False):

source

FileIO.write2file

 FileIO.write2file (outfile:str=None, outlayer:str=None, driver:str=None,
                    crs:str=None, perc:float=None, tol:float=None)

Write the concave hull polygon to a file.

Parameters: outfile (str) : The file name of the output file. If not specified it will be named concave_hull
outlayer (str): The name of the layer in the output file where applicable
driver (str) : See table above on possible driver options Only drivers with w in the mode can be used. Drivers other than the ‘mainstream’ my vary in success.
crs (str) : the coordinate reference system in WKT format. Not essential
perc (float) : Will calculate the concave hull using this percentile on the triangle edges. See the estimate method in ConcaveHull.
tol (float) : Will calculate the concave hull using this length tolerance. See the calculatehull method in ConcaveHull.

Returns: None

Example Usage

Files in the examples folder

files = os.listdir('../examples')
files.sort()
for file in files:
    print(file)
BANDELIER 8.dxf
BANDELIER8.TXT
Bandelierkop_survey.cpg
Bandelierkop_survey.dbf
Bandelierkop_survey.prj
Bandelierkop_survey.qmd
Bandelierkop_survey.shp
Bandelierkop_survey.shx
points-1k.json
fch = FileIO()
fch.file2points('../examples/BANDELIER 8.dxf')
fch.write2file()
fch = FileIO()
fch.file2points('../examples/Bandelierkop_survey.shp')
fch.calculatehull(tol=35)
fch.write2file()
print(len(fch.triangles))
print()
15984

CPU times: user 1.09 s, sys: 16.4 ms, total: 1.1 s
Wall time: 1.09 s