2
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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"}]

enter image description here

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"]

enter image description here

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:

enter image description here

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:

enter image description here

GeoRegionValuePlot[AssociationThread[
  geom,
  Association[
    Association[
      Import["~/Downloads/Estrada/estrada.shp", {"SHP", "Data"}]][
     "LabeledData"]]["SUPERFICIE"]]]

enter image description here

Finally, though this is a Mathematica forum, here is how to generate similar plots in QGIS, since you mentioned it:

enter image description here

giving

enter image description here

You asked the right person ;)

$\endgroup$
  • $\begingroup$ Yes I unzipped files but I can´t load the names. Thank you for the advices, i´m trying $\endgroup$ – Mika Ike Apr 16 at 14:29
  • 1
    $\begingroup$ @MikaIke See my edit. 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 has a single layer. $\endgroup$ – Carl Lange Apr 16 at 14:32
  • $\begingroup$ I have no the SRS option. I must revise what you explain, and leearn more about shp. i.postimg.cc/wxFh5vFy/snapw01145.jpg $\endgroup$ – Mika Ike Apr 16 at 14:43
  • $\begingroup$ @MikaIke, What country is this data for? That will help to narrow down what the SRS should be. $\endgroup$ – Carl Lange Apr 16 at 14:46
  • $\begingroup$ for the northwest of Spain (South of Europe), at the north of Portugal. $\endgroup$ – Mika Ike Apr 16 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.