Shapefile importer
Shapefile importer
With git commit 916a42397c there is now (part of the Arch workbench) an importer for Shapefiles, which are commonly used by GIS applications.
The importer uses the shapefile.py library from https://github.com/GeospatialPython/pyshp, it is not found on your system on first run, the importer will propose to download and install it for you.
Shapefiles are composed of 3 files (a .shp, a .shx and a .dbf file), any of them can be used with this importer. They are composed of 2D objects of one geometry type, that can be polygons/faces, polylines or point cloud (all 3 types are supported by this importer), and custom fields, for which each face, polyline or point in the shapefile has a value. This is the real gem of GIS, to bind a database with geometry. The most common use is to have one field to represent the elevation coordinate of each shape in the file. On opening the file, the importer will ask you what field to get shape elevations from.
Note that there is all the question of georeferenced units, with hundreds of projection systems used worldwide, which are not treated at the moment. The coordinates from the file are used "as is".
The importer uses the shapefile.py library from https://github.com/GeospatialPython/pyshp, it is not found on your system on first run, the importer will propose to download and install it for you.
Shapefiles are composed of 3 files (a .shp, a .shx and a .dbf file), any of them can be used with this importer. They are composed of 2D objects of one geometry type, that can be polygons/faces, polylines or point cloud (all 3 types are supported by this importer), and custom fields, for which each face, polyline or point in the shapefile has a value. This is the real gem of GIS, to bind a database with geometry. The most common use is to have one field to represent the elevation coordinate of each shape in the file. On opening the file, the importer will ask you what field to get shape elevations from.
Note that there is all the question of georeferenced units, with hundreds of projection systems used worldwide, which are not treated at the moment. The coordinates from the file are used "as is".
Re: Shapefile importer
Great work!
::bitacovir::
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)
Canal Youtube Grupo Telegram de FreeCAD Español
My personal web site
My GitHub repository
Mini Airflow Tunnel Project
==================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)
Canal Youtube Grupo Telegram de FreeCAD Español
My personal web site
My GitHub repository
Mini Airflow Tunnel Project
Re: Shapefile importer
Well done!
Re: Shapefile importer
Nice! I noticed that the Civil Engineering thread was looking into georeferencing recently.
Re: Shapefile importer
I am curious. Do you have a special project you need this for?
- HakanSeven12
- Veteran
- Posts: 1480
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Shapefile importer
Good. Does it move objects to their real coordinates or does it reduce the coordinates to origin?
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Re: Shapefile importer
You may already understand this so I am thinking out loud in public here. My understanding is the "origin" in a shapefile is the origin of the coordinate reference system (crs). I suppose the importer could create a bounding box of all the geometry and import it to the center or a corner. I need to try it out and see how it works.
Re: Shapefile importer
Nice. There is a little issue when selecting "None" for the elevation value field. See the PR here: https://github.com/FreeCAD/FreeCAD/pull/3550.
Oh, and I another issue: The shapefile reader operates in "strict" Unicode decoding mode by default. This means any wrongly encoded stuff, it will throw UnicodeDecodeError. You could either catch and handle this, or change the mode to "ignore", "replace" or "backslashreplace" on init of the reader: Would include this in the PR, but am undecided which option is best. Any thoughts?
In addition, we could also ask for the encoding (together with the elevation field) and pass it explicitly to the reader in case the user wants not Unicode:.
Oh, and I another issue: The shapefile reader operates in "strict" Unicode decoding mode by default. This means any wrongly encoded stuff, it will throw UnicodeDecodeError. You could either catch and handle this, or change the mode to "ignore", "replace" or "backslashreplace" on init of the reader:
Code: Select all
shp = shapefile.Reader(filename, encodingErrors='ignore')
In addition, we could also ask for the encoding (together with the elevation field) and pass it explicitly to the reader in case the user wants not Unicode:
Code: Select all
shp = shapefile.Reader(filename, encoding='latin1')
Re: Shapefile importer
Hi, I was happy to find the option to import shape files.
However it seems that the import distorts the shape file in my case. Any Idea why this happens? When asked for elevation field, i selected "None" because I don't know whether my file has any elevation data (only the fields: id, deletionFlag, none can be selcted).
The shape file display in QGIS: The same shape file display in FreeCAD after import: I use FreeCAD 0.19 on Mac OS X 10.15.7 and I'm a beginner in FreeCad used other cad software before (on my way to use more open source software).
However it seems that the import distorts the shape file in my case. Any Idea why this happens? When asked for elevation field, i selected "None" because I don't know whether my file has any elevation data (only the fields: id, deletionFlag, none can be selcted).
The shape file display in QGIS: The same shape file display in FreeCAD after import: I use FreeCAD 0.19 on Mac OS X 10.15.7 and I'm a beginner in FreeCad used other cad software before (on my way to use more open source software).
- HakanSeven12
- Veteran
- Posts: 1480
- Joined: Wed Feb 06, 2019 10:30 pm
Re: Shapefile importer
I'm thinking the reason is your coordinate values are so big. So standard freecad objects can't render it properly.
Support me: Hakan Seven on Patreon
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum
Modern UI: Modern UI on FreeCAD Forum
Trails Workbench: Trails Workbench on FreeCAD Forum