After saving (with QGis) the part of the map I´m interested in for a local visualization, I have the .zip file where you can see 5 files. I load the map in Mathematica with
e1 = Import["Estrada.zip"]
all works fine.
But the problem is... when I want to list the name of every region, I can´t find the names, but I can see LayerNames if I type
e2 = Import["Estrada.zip","Elements"]
zip file at https://we.tl/t-NqBdMYcOSN (sorry for not attanching to the message, if I must upload the file to another site, please tell me)
I´m doing bad anything or is not available the LayerName in this zip file?
Answer
It does appear that "LayerNames"
does not work correctly with Shapefile zips - I would recommend emailing WRI support about this, as I think it's a bug.
As a workaround, you can unzip the shapefile zip and import the .shp
inside instead of importing the zip file.
I uncompressed the zip file locally (just by double-clicking the zip file), and then I can do:
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "LayerNames"}]
"estrada"
Which (I checked) is the only layer in the file.
You can get the Graphics object like so:
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Graphics"}]
and the data like so:
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Data"}]
For example, you can get the names of each area by doing:
Association[
Association[
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Data"}]][
"LabeledData"]]["PARROQUIA"]
By the way, "LayerNames"
may not be what you think they are. They are the names of layers in the shapefile, rather than objects within a layer. The file you have only shows a single layer. In QGIS, you can see this in the bottom left:
One thing to note: your data purports to be, but is not, in the EPSG:4326 spatial reference system. I would recommend exporting in this SRS if you wish to use the geospatial data within Mathematica.
I have determined that your data is in the UTM Zone 29 SRS (EPSG:32629). You can set this as such in QGIS and export as 4326, or you can happily use these positions in Mathematica, now that we know what they are.
To use this in Mathematica, we need GeoGridPosition
.
Let's convert the geometry in the Data
field to GeoGridPosition
:
geom = Association[
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Data"}]][
"Geometry"] /.
Polygon[x_] :> (Polygon[GeoGridPosition[#, "UTMZone29"] & /@ x])
Now we can use it like any normal GeoPosition
:
GeoRegionValuePlot[AssociationThread[
geom,
Association[
Association[
Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Data"}]][
"LabeledData"]]["SUPERFICIE"]]]
Finally, though this is a Mathematica forum, here is how to generate similar plots in QGIS, since you mentioned it:
giving
Comments
Post a Comment