Difference between revisions of "Shapefiles"

From Navit's Wiki
Jump to: navigation, search
m (OpenStreetMap: spelling)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
=== Renameing Idea ===
+
= Using Shapefile maps directly in Navit =
  
Creating symlink to the actual file to let navit acces the right file
+
Is it possible to use shapefile maps directly in Navit.
 +
You will need to create a .dbfmap file to tell Navit how to read your shapefile.
  
<pre>
+
Shapefile usually come as a group of files, each file focusing on one specific set of feature.
cd maps/shapefiles/
 
  
for i in *.shx; do ln -s $i ${i%.*}.cpg.shx; done
+
For example, an OpenStreetMap Shapefile export will contain the following files:
for i in *.shp; do ln -s $i ${i%.*}.cpg.shp; done
 
  
 +
$ ls *.shp
 +
gis.osm_buildings_a_free_1.shp  gis.osm_pofw_a_free_1.shp    gis.osm_traffic_a_free_1.shp
 +
gis.osm_landuse_a_free_1.shp    gis.osm_pofw_free_1.shp      gis.osm_traffic_free_1.shp
 +
gis.osm_natural_a_free_1.shp    gis.osm_pois_a_free_1.shp    gis.osm_transport_a_free_1.shp
 +
gis.osm_natural_free_1.shp      gis.osm_pois_free_1.shp      gis.osm_transport_free_1.shp
 +
gis.osm_places_a_free_1.shp    gis.osm_railways_free_1.shp  gis.osm_water_a_free_1.shp
 +
gis.osm_places_free_1.shp      gis.osm_roads_free_1.shp    gis.osm_waterways_free_1.shp
  
for i in *.dbf; do ln -s $i "${i##*.}"dbfmap; done
+
For this example we will focus on loading the streets from the "gis.osm_roads_free_1.shp" file.
for i in *.dbf; do ln -s $i "${i##*.}"map; done
 
for i in *.dbf; do ln -s $i ${filename%.*}dbfmap; done
 
for i in *.dbf; do ln -s $i ${i%.*}.dbfmap; done #<-- right?!
 
for i in *.shx; do ln -s $i ${i%.*}.cpg.shx; done
 
for i in *.shp; do ln -s $i ${i%.*}.cpg.shp; done
 
</pre>
 
This is NOT a solution, this was only a first try!
 
  
=== Logs about shapefiles until we can write a proper documentation ===
+
Add a mapset to your navit.xml file. Mapsets are defined around line 420 of the default navit.xml
  
<pre>
+
'''Note : you need to disable any other mapset that could be already enabled'''
juin 05 08:07:33 <stem> hello
 
juin 05 08:08:15 <stem> any one worked on shape file ?
 
juin 05 08:09:21 <stem> we are facing problem while using shapefile in navit
 
juin 05 08:10:21 <stem> Can any one help
 
juin 05 08:24:48 <cp15> Stem, what is the problem?
 
juin 05 08:25:10 <cp15> You need to create a .dbfmap file where you define the mapping between shapefile objects and navit objects
 
juin 05 08:25:38 <stem> ya thats the problem
 
juin 05 08:26:04 <stem> how to create the dbfmap file using dbf file
 
juin 05 08:26:14 <stem> actually i ahve dbf file
 
juin 05 08:26:48 <cp15> It should contain something like this:
 
juin 05 08:26:50 <stem> but the problem is  to create dbfmap from dbf
 
juin 05 08:26:52 <cp15> OBA=2227        type=poly_park label=${GN}
 
juin 05 08:27:17 <cp15> (separator between OBA=2227 and type=... must be a tab
 
juin 05 08:28:05 <cp15> Which means that all objects which have OBA=2227 in their dbf file are mapped to a poly_park with a label of the gn field of dbf
 
juin 05 08:28:40 <cp15> You can specify multiple keys on the left side, for example
 
juin 05 08:29:05 <cp15> OBA=2227,SUBTYPE=1        type=poly_park label=${GN}
 
juin 05 08:29:26 <cp15> If there are multiple matches the longest one (with the most keys) will be used
 
juin 05 08:29:51 <cp15> Once you get it working, maybe you could document it in our wiki?
 
juin 05 08:32:12 <stem> so you mean to say that dbfmap must be created by us, as you said ...
 
juin 05 08:32:28 <stem> manually...
 
juin 05 08:32:52 <cp15> Since there is no scheme what has to be in the .dbf, yes
 
juin 05 08:33:10 <cp15> You can uncomment the unknown stuff in navit.xml so you will see all objects
 
juin 05 08:33:29 <cp15> Then change the gui to gtk and you can right-click on a object and it will show you the dbf key and values
 
juin 05 08:34:04 <cp15> Then you can add then to the .dbfmap as needed. As soon as you redraw the map the new entries will be used
 
juin 05 08:34:32 <cp15> Ah, and you have to take care to get the right projection. What projection does your shapefile have?
 
juin 05 08:37:56 <stem> GEOGCS["Lat Long WGS84",DATUM["D_WGS_1984",SPHEROID["World Geodetic System of 1984",6378137.0,298.257222932867]],PRIMEM["Greenwich",0.0],UNIT["degree",0.0174532925199433]]
 
juin 05 08:38:19 <stem> this is what projection file reads...
 
juin 05 08:41:17 <cp15> Ok, that is the default
 
juin 05 08:44:20 <stem> For creating dbfmap, should i need to cnsider all the prj , dbf,  shp file and then edit those parameters in bdfmap file and feed this to navit
 
juin 05 08:48:10 <stem> do you feel we can use shapefile in navit without any problem or any other tatics to convert shapefile to binfile
 
juin 05 09:53:10 <cp15> stem, you can use maptool to convert shapefiles to navit binfiles, but you need the dbfmap anyways
 
  
</pre>
+
<mapset enabled="yes">
 +
  <map type="shapefile" enabled="yes" data="$NAVIT_SHAREDIR/maps/shapefile/gis.osm_roads_free_1" />
 +
</mapset>
 +
 
 +
'''Note : do not include the ".shp" extension''' otherwise Navit will complain with
 +
error:map_shapefile:VSI_SHP_Error:error:Unable to open maps/shapefile/gis.osm_roads_free_1.shp.shp or maps/shapefile//gis.osm_roads_free_1.shp.SHP.
 +
 
 +
Now we need to create the relevant .dbfmap. If you use features from different files (e.g streets from gis.osm_roads_free_1, water polys from gis.osm_water_a_free_1 ) then you will need to create one .dbfmap file for each shp file.
 +
 
 +
Here is a minimalistic gis.osm_roads_free_1.dbfmap :
 +
code=5111 type=highway_land label=${name}
 +
code=5112 type=street_1_city label=${name}
 +
code=5113 type=street_2_city label=${name}
 +
code=5114 type=street_3_city label=${name}
 +
code=5115 type=street_4_city label=${name}
 +
code=5122 type=living_street label=${name}
 +
 
 +
'''Note : the first field (code, in this example) and the type field must be separated by a tabulation, not spaces.'''
 +
 
 +
= How can I find the field name and value to use? =
 +
The content of your .dbfmap will vary depending of your map source. One way to analyze shapefile tags is to use QGis
 +
 
 +
In this example, we are loading again the shapefile from OpenStreetMap. When displaying the streets, we can select one specific segment and look at its tag. In this example, we can see the street name is under the "name" tag (used in label=${name}) and the code=5122 which would correspond to a "living_street" in Navit. Highlighting several segments of the same street might help identify which tag ("code" here) and which value (5122 here) to use.
 +
 
 +
[[File:Qgis.png]]
 +
 
 +
The resulting map would look like this :
 +
 
 +
[[File:Shapefile.png]]
 +
 
 +
This is a minimalistic example, as only some (not all) of the roads are mapped using our example .dbfmap

Latest revision as of 20:45, 29 August 2019

Using Shapefile maps directly in Navit[edit]

Is it possible to use shapefile maps directly in Navit. You will need to create a .dbfmap file to tell Navit how to read your shapefile.

Shapefile usually come as a group of files, each file focusing on one specific set of feature.

For example, an OpenStreetMap Shapefile export will contain the following files:

$ ls *.shp
gis.osm_buildings_a_free_1.shp  gis.osm_pofw_a_free_1.shp    gis.osm_traffic_a_free_1.shp
gis.osm_landuse_a_free_1.shp    gis.osm_pofw_free_1.shp      gis.osm_traffic_free_1.shp
gis.osm_natural_a_free_1.shp    gis.osm_pois_a_free_1.shp    gis.osm_transport_a_free_1.shp
gis.osm_natural_free_1.shp      gis.osm_pois_free_1.shp      gis.osm_transport_free_1.shp
gis.osm_places_a_free_1.shp     gis.osm_railways_free_1.shp  gis.osm_water_a_free_1.shp
gis.osm_places_free_1.shp       gis.osm_roads_free_1.shp     gis.osm_waterways_free_1.shp

For this example we will focus on loading the streets from the "gis.osm_roads_free_1.shp" file.

Add a mapset to your navit.xml file. Mapsets are defined around line 420 of the default navit.xml

Note : you need to disable any other mapset that could be already enabled

<mapset enabled="yes">
 <map type="shapefile" enabled="yes" data="$NAVIT_SHAREDIR/maps/shapefile/gis.osm_roads_free_1" />
</mapset>

Note : do not include the ".shp" extension otherwise Navit will complain with

error:map_shapefile:VSI_SHP_Error:error:Unable to open maps/shapefile/gis.osm_roads_free_1.shp.shp or maps/shapefile//gis.osm_roads_free_1.shp.SHP.

Now we need to create the relevant .dbfmap. If you use features from different files (e.g streets from gis.osm_roads_free_1, water polys from gis.osm_water_a_free_1 ) then you will need to create one .dbfmap file for each shp file.

Here is a minimalistic gis.osm_roads_free_1.dbfmap :

code=5111	type=highway_land label=${name}
code=5112	type=street_1_city label=${name}
code=5113	type=street_2_city label=${name}
code=5114	type=street_3_city label=${name}
code=5115	type=street_4_city label=${name}
code=5122	type=living_street label=${name}

Note : the first field (code, in this example) and the type field must be separated by a tabulation, not spaces.

How can I find the field name and value to use?[edit]

The content of your .dbfmap will vary depending of your map source. One way to analyze shapefile tags is to use QGis

In this example, we are loading again the shapefile from OpenStreetMap. When displaying the streets, we can select one specific segment and look at its tag. In this example, we can see the street name is under the "name" tag (used in label=${name}) and the code=5122 which would correspond to a "living_street" in Navit. Highlighting several segments of the same street might help identify which tag ("code" here) and which value (5122 here) to use.

Qgis.png

The resulting map would look like this :

Shapefile.png

This is a minimalistic example, as only some (not all) of the roads are mapped using our example .dbfmap