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!
User avatar
yorik
Site Admin
Posts: 12055
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Shapefile importer

Postby yorik » Fri May 08, 2020 11:09 am

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
Posts: 1155
Joined: Sat Apr 19, 2014 6:23 am
Contact:

Re: Shapefile importer

Postby bitacovir » Fri May 08, 2020 12:21 pm

Great work!
::bitacovir::
===================================
One must be absolutely modern.
Arthur Rimbaud (A Season in Hell -1873)

My personal web site
My GitHub repository
My old Blog
Mini Airflow Tunnel Project
fc_tofu
Posts: 654
Joined: Sun Jan 05, 2020 4:56 pm

Re: Shapefile importer

Postby fc_tofu » Fri May 08, 2020 4:31 pm

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

Re: Shapefile importer

Postby baswein » Fri May 08, 2020 7:35 pm

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

Re: Shapefile importer

Postby bernd » Fri May 08, 2020 10:11 pm

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

Re: Shapefile importer

Postby HakanSeven12 » Sat May 09, 2020 7:04 am

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

Re: Shapefile importer

Postby baswein » Sat May 09, 2020 4:13 pm

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

Re: Shapefile importer

Postby hlg » Tue Jun 02, 2020 3:37 pm

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') 
.