QGIS import and export GPX

import is simple – just open the gpx-file with double click in the qgis-browser

export (lines)

  • right-click on the layer
  • save as…
    • Format: GPS eXchange Format [GPX]
    • Save as …
    • CRS: Selected CRS (coordinate reference system)
    • (do not „Add saved file to map“)
    • OK

export (points)

if you want to export points to GPX and get the following error – welcome 🙂

Export to vector file failed.
Error: creation of layer failed (OGR error:Geometry type of `Multi Point' not supported in GPX.)

i found this bug-fix and my workaround is to use the following script from the toolbox (menu Processing – Toolbox (on the bottom „Advanced Interface“))

  • GDAL/OGR – OGR Conversion – Conversion format

i added these additional commands to „creation options“:

GPX_USE_EXTENSIONS=YES -explodecollections
processing.runalg("gdalogr:convertformat","/Users/me/QGIS/test.shp",16,"-dsco GPX_USE_EXTENSIONS=YES -explodecollections","/Users/me/QGIS/test.gpx")

export the gpx file as a script via python run the following in your python-console

import processing
processing.runalg("gdalogr:convertformat","/Users/me/QGIS/test.shp",16,"-dsco GPX_USE_EXTENSIONS=YES -explodecollections","/Users/me/QGIS/test.gpx")

.

Advertisements

postgresql with OSM on raspberryPI

follow these instruction (german) to install all you need for your own osm-server

install postgresql

first update

  sudo apt-get update
then install the package; about 21MB additional space will be used
  sudo apt-get install postgresql
after that the server should report
  [ ok ] Starting PostgreSQL 9.1 database server: main.
here are some steps to configure the server
install tools for osm
install imposm git postgis and postgresql-9.1-postgis
  sudo apt-get install postgis imposm git postgresql-9.1-postgisnow create a source directory and download osm data
  mkdir ~/src
  cd ~/src && wget http://download.geofabrik.de/europe/slovenia-latest.osm.pbfdownload the following tool, needed later
cd ~/src && git clone https://github.com/mapbox/osm-bright.git

 

run the following scritp as postgres-user, so first create a sh-file
  set -xe
  createuser –no-superuser –no-createrole –createdb osm
  createdb -E UTF8 -O osm osm
  createlang plpgsql osm
  psql -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
  psql -d osm -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
  psql -d osm -f /usr/share/python-imposm/900913.sql
  echo „ALTER TABLE geometry_columns OWNER TO osm; ALTER TABLE spatial_ref_sys OWNER TO osm;“ |psql -d osm
  echo „ALTER USER osm WITH PASSWORD ‚osm‘;“ |psql -d osm
  set +x
then login as postgres
  sudo su postgres
  sh ./create_db.sh
  exit

now add the following row to your postgre config and restart postgre
  sudo nano /etc/postgresql/9.1/main/pg_hba.conf
  host osm osm 127.0.0.1/32 md5
  sudo /etc/init.d/postgresql restart

to import your first data use (more infos here)
imposm –-read –-write –-optimize -h localhost -p 5432 -d osm -m ~/src/osm-bright/imposm-mapping.py ~/src/slovenia-latest.osm.pbf
this will need quite a time – in my case
  imposm took 2 h 40m 44s

in the mean time you can check your database for new created tables after the message ## dropping/creating tables

in psql you can view your tables with (\connect osm;)

get the version of postgis

SELECT PostGIS_full_version();

postgis_full_version

——————————————————————————————————-

POSTGIS=“1.5.3″ GEOS=“3.3.3-CAPI-1.7.4″ PROJ=“Rel. 4.7.1, 23 September 2009″ LIBXML=“2.8.0″ USE_STATS

(1 row)

  SELECT table_name FROM information_schema.tables WHERE table_schema = ‚public‘;

      table_name
————————–
 spatial_ref_sys
 geometry_columns
 geography_columns
 osm_new_mainroads
 osm_new_buildings
 osm_new_amenities
 osm_new_aeroways
 osm_new_motorways
 osm_new_transport_points
 osm_new_landusages
 osm_new_waterways
 osm_new_railways
 osm_new_waterareas
 osm_new_places
 osm_new_admin
 osm_new_barrierways
 osm_new_minorroads
 osm_new_barrierpoints
 osm_new_roads

get column names from a table
  SELECT column_name FROM information_schema.columns WHERE table_name=’osm_new_roads‘;

 column_name
————-
 class
 type
 access
 z_order
 layer
 oneway
 tunnel
 ref
 bridge
 name
 geometry
 osm_id
 id

and easy to find different types
  SELECT type, COUNT(*)  FROM osm_new_roads GROUP BY type ORDER BY type;

      type      | count
—————-+——-
 bridleway      |     1
 cycleway       |    38
 footway        |   855
 living_street  |    27
 motorway       |   171
 motorway_link  |   247
 path           |   318
 pedestrian     |   139
 primary        |   283
 primary_link   |    26
 rail           |   128
 residential    |  2683
 road           |     5
 secondary      |   581
 secondary_link |    12
 service        |   593
 steps          |    60
 tertiary       |   888
 tertiary_link  |     2
 track          |  1820
 trunk          |    47
 trunk_link     |    47
 unclassified   |  1397
(23 rows)

after the import finished turn your *new* tables to operational tables – WARNING old data will be lost!
  imposm –deploy-production-tables -d osm

lets create tiles

go to the folder ~/src/osm-bright and rename
  mv configure.py.sample configure.py

edit the config file
config[„importer“] = „imposm“
config[„postgis“][„host“]     = „localhost“
config[„postgis“][„port“]     = „5432“
config[„postgis“][„dbname“]   = „osm“
config[„postgis“][„user“]     = „osm“
config[„postgis“][„password“] = „osm“
download additional files to ~/src/osm-bright (coastline has ~310MB, shoreline ~45MB, 10m-land 5MB)

  wget http://tilemill-data.s3.amazonaws.com/osm/coastline-good.zip
wget http://tilemill-data.s3.amazonaws.com/osm/shoreline_300.zip
wget http://mapbox-geodata.s3.amazonaws.com/natural-earth-1.3.0/physical/10m-land.zip

create this dir
  mkdir ~/Documents/MapBox/project

psql

get server version
  select version();
PostgreSQL 9.1.14 on armv7l-unknown-linux-gnueabihf, compiled by gcc (Debian 4.6.3-14+rpi1) 4.6.3, 32-bit
  CREATE DATABASE mydb;
response: CREATE DATABASE
drop a database
  DROP DATABASE mydb;
  CREATE TABLE account(
    user_id serial PRIMARY KEY,
    username VARCHAR (50) UNIQUE NOT NULL,
    password VARCHAR (50) NOT NULL,
    email VARCHAR (355) UNIQUE NOT NULL,
    created_on TIMESTAMP NOT NULL,
    last_login TIMESTAMP
  );
as you see, squences, keys and uniques will be generated automatically
drop table also dropps all autogenerated objects
get tablenames
  SELECT table_name FROM information_schema.tables WHERE table_schema = ‚public‘;useful documentation to access postgres from external device (eg qgis…)
important commands/files for postgre
config file
  sudo nano /etc/postgresql/9.1/main/pg_hba.conf
restart server
  sudo /etc/init.d/postgresql restart
enter server with psql
  psql -U postgres
exit with CTRL-D
show data align after the query
  -S

manual installation of postGIS

download from http://postgis.net/source
sudo apt-get install libpq-dev libproj-dev postgresql-server-dev-9.1
install geos and gdal – see http://northwestspatial.com/wp/?p=340
download source
./configure
sudo make install
test it with
geos-config –version
gdal-config –version
then update apt-get
sudo ldconfig
download source for postGIS and

./configure –with-topology –with-raster
sudo make install
restart postgresql
sudo service postgresql restart

use this documentation to install postGIS to postgresql
http://postgis.net/docs/manual-2.1/postgis_installation.html#install_short_version

Use RaspberryPi to convert OSM data to GARMIN format img

thanks to java-support in raspberry pi Linux 3.10.25+ armv6l it is quite easy to convert osm-files to img files.

1. download mkgmap jar-file and unzip it bzip2 -d malta-latest.osm.bz2
2. download osm data (eg from here or other sources listed here) and save it to osm-folder
3. go to your img-folder convert the file using
  java -jar ../mkgmap/mkgmap.jar ../osm/malta-latest.osm 

i had the following result:
  Time started: Fri Jun 19 11:22:54 CET 2014
  Number of MapFailedExceptions: 0
  Number of ExitExceptions: 0
  Time finished: Fri Jun 19 11:26:58 CET 2014
  Total time taken: 244294ms

4. now the img file can be used with basecamp…

Serial Data Connection on Raspberry Pi with GARMIN GPS 12

GARMIN GPS 12

the idea is to read and write data from the GARMIN GPS 12 via raspberry pi. the GPS 12 has 4 pins at the back: POWER, GROUND, DATA IN and DATA OUT. powering the GPS-unit as follows:

Raspberry pi wiring diagram
wire POWER to 5V and GROUND to GND
GARMIN GPS 12 unit view

Next step will be to establish a data connection… create your own cable https://www.syz.com/gps/gpsinfo.pdf http://www.savagehomeautomation.com/projects/raspberry-pi-rs232-serial-interface-options-revisit.html http://pi4j.com/example/serial.html http://elinux.org/RPi_Serial_Connection

https://www.raspberrypi.org/forums/viewtopic.php?t=11228&p=129224 http://pi4j.com/example/serial.html

i gave it up to try it with the old GPS 12. now i try to get GPS-data with the newer GPSMAP 64s.
on the gps-unit go into your settings and set interface to „Garmin Spanner“ – so you can choose after usb-connection if you want storage-mode, yes or no.
after plugging usb to raspi, i see it with „Garmin International GPS (various models)“ after the lsusb-command.

after that i installed gpsd gpsd-clients python-gps
sudo apt-get install gpsd gpsd-clients python-gps
start the daemon (important is the -n switch!)
sudo gpsd /dev/ttyUSB0 -F /var/run/gpsd.sock -n
and connect to the gps-unit
now get gps-data with
gpsmon /dev/ttyUSB0

kill the daemon
sudo killall gpsd

do not run gpsmon and gpsd simultaniously

infos from here and here

https://www.raspberrypi.org/forums/viewtopic.php?t=48345&p=382294

garmin basecamp create tour/route/track

  1. create your track with you favourite tracking-software (basecamp, movescount, gpsies, google-maps, etc.) but be sure to be able to export in gpx/kml.
  2. import the route/track in basecamp
  3. count the number of points in your track – old garmin-devices do not support:
    1. routes (for navigation) with more than 250 points
    2. tracks (just overlay) with more than 500 points
      (results in auto-truncation)
  4. reduce point-numbers manually or with the following tool: http://www.gpsies.com/convert.do
    be sure, that important crossings still have enough details for navigation. 
  5. if your file (eg. rome_florence) still has too many point, duplicate your file and rename all files (rome_florence1, rome_florence2 …)
  6. now delete the points in each duplicated route so that every route has not more than 250 or 500 points for routes or track-usage.
  7. transfer the files to your device and check them on the map
TIPs

  1. avoid same names for tracks and routes

! ! happy navigation ! !

embedded maps

Results

comparing google maps, vienna maps and openstreetmaps: these three sites offer more or less easy access to the html-embedded maps. take a look at the different zoom-level: osm and google use the same zoom where the vienna map has more overview an also displays more street names. vienna map is the only site that offers the mapscale and uses a single link to the useragreements. the other sites have more text on the bottom – you can read „google“ three times on the bottom!!!

Google Maps maps.google.com

  • embedded code with html-iframe container. basic version with width and height configuration (small, middle, large, user-defined). 
  • sample: search for „ottakringerstraße 89, wien“ and press the „link“-button on the left. in this sample you get a bubble, which is not very nice 😦

[googlemaps https://maps.google.de/maps?f=q&source=s_q&hl=de&geocode=&q=ottakringerstra%C3%9Fe+89,+wien&aq=&sll=47.394203,13.68544&sspn=0.081925,0.124969&ie=UTF8&hq=&hnear=Ottakringer+Stra%C3%9Fe+89,+Ottakring+1160+Wien,+%C3%96sterreich&t=m&ll=48.213349,16.323709&spn=0.017158,0.025749&z=14&iwloc=A&output=embed“ width=“300″>
Größere Kartenansicht

Vienna map (OGD) wien.gv.at/stadtplan

  • embedded code with html-div container and java-script. basic version has also width and height configuration (small, middle, large, user-defined). 
  • sample: search for „ottakringerstraße 89“ and press the link on the top „Link/Einbetten“. here is the result:

OpenStreetMap openstreetmap.org

  • embedded code with html-iframe container. no easy configuration of width and height but the possibility to add a marker
  • sample: search for „ottakringerstraße 89, wien“ (bad result list and not correct street number). to get to the embedded-code: click „export“ on the top, then choose „embedded HTML“ on the left, and then you can add the marker and copy the HTML-code. here is the result with the marker

Other Map-Services
Italien map
http://www.pcn.minambiente.it

garmin maps installation on sd-card

in the root-folder of the sd-card, you find all GPX-files (tracks per day), saved by the garmin-device.

in the folder Garmin you find the file gmapsupp.img with the map information installed by map-source or other map-creation-tools.

very cool site to create img-files is http://garmin.openstreetmap.nl/

i tried it with my GPSMAP 60CSX and it word (very) fine!!

** ** WARNING ON MAC ** **
after editing the img file(s) on the sd-card be sure there are no .Trash-Folder(s) etc. on the card. these folders result in carshing of the 60CSX!!!

ls -a
rm -R .S*
rm -R .T*
rm -R .f*

to combine old maps (eg NT Europe, TOPO…) do the following.

Start the GMapTool (Only windows 😦
Select/add the file with the OSM data (eg gmapsuppOSM.img) and the file with your MapSource-data (eg gmapsuppTOPONT.img)
On the combine-tab choose your outputfile (eg gmapsupp.img) and press combine all.

then copy the outputfile to your garmins sd-card (/garmin/) and be happy!