Shapefile importer

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Shapefile importer

Post by yorik »

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".
User avatar
bitacovir
Veteran
Posts: 1570
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Shapefile importer

Post by bitacovir »

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
fc_tofu
Posts: 653
Joined: Sun Jan 05, 2020 4:56 pm

Re: Shapefile importer

Post by fc_tofu »

Well done!
baswein
Posts: 21
Joined: Mon Aug 26, 2019 4:26 pm

Re: Shapefile importer

Post by baswein »

Nice! I noticed that the Civil Engineering thread was looking into georeferencing recently.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Shapefile importer

Post by bernd »

I am curious. Do you have a special project you need this for?
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Shapefile importer

Post by HakanSeven12 »

Good. Does it move objects to their real coordinates or does it reduce the coordinates to origin?
baswein
Posts: 21
Joined: Mon Aug 26, 2019 4:26 pm

Re: Shapefile importer

Post by baswein »

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.
User avatar
hlg
Posts: 39
Joined: Fri Jul 12, 2019 10:11 am

Re: Shapefile importer

Post by hlg »

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:

Code: Select all

shp = shapefile.Reader(filename, encodingErrors='ignore') 
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:

Code: Select all

shp = shapefile.Reader(filename, encoding='latin1') 
.
ocapitor
Posts: 1
Joined: Sat Jul 24, 2021 10:52 am

Re: Shapefile importer

Post by ocapitor »

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:
QGis
QGis
Bildschirmfoto 2021-07-24 um 14.09.16.png (46.89 KiB) Viewed 9776 times
The same shape file display in FreeCAD after import:
FreeCad
FreeCad
Bildschirmfoto 2021-07-24 um 14.10.49.png (31.71 KiB) Viewed 9776 times
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).
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: Shapefile importer

Post by HakanSeven12 »

I'm thinking the reason is your coordinate values are so big. So standard freecad objects can't render it properly.
Post Reply