Using OSM with PostGIS

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Using OSM with PostGIS

Alex Willmer
I've taken a first stab at loading OpenStreetMap data into PostGIS, the
geospatial extension to Postgresql.

Instructions and the script are on the wiki:
http://wiki.openstreetmap.org/index.php/User:Moreati

It's rough and barely functional at the moment. If anyone is interested
I'll clean it up and release it properly.

I have the planet.osm data loaded, I've not yet seen it. If you manage
to connect please take a screenshot and post it to the wiki. I'll do the
same once I get QGIS working again.

Regards,
 
Alex


_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Johnny Doe-2

--- Alex Willmer <[hidden email]>

> If you manage
> to connect please take a screenshot and post it to
> the wiki. I'll do the
> same once I get QGIS working again.
>

The easiest way to import the planet.osm into Qgis is
to convert it into mapinfo format. It is very simple
and does not require any bizarre tools.
Parsing the tags and splitting into the layers is
left as an exersise to the reader.
If the layers are split, then you can produce the
"point" and "linestring" shapefiles with ogr2ogr:
ogr2ogr -f "esri shapefile" nodes.shp nodes.mif
ogr2ogr -f "esri shapefile" segments.shp segments.mif

------------------------------
#!/bin/bash
awk -F\" 'BEGIN{
 i=-1;j=-1;
 system("rm -f planet.mi?");
printf("version 300\ncharset \"utf-8\"\n\
coordsys earth projection 1, 104\n\
delimiter \",\"\n\
columns 1\n\
cat integer\n\
data\n") >"planet.mif";
}
{
        if ($1 == "  <node id=")
         {
          nodes[i++]=$2; nodelat[$2]=$4;
          nodelon[$2]=$6;
         }
        if ($1 == "  <segment id=")
         {
          seg[j++]=$2; seg_start[j]=$4;
          seg_end[j]=$6;
         }
}
END{
for(k=0;k<i;k++)
{
 print "point",nodelat[nodes[k]],nodelon[nodes[k]] >>
"planet.mif"
 print nodes[k] >> "planet.mid"
}
for(k=0;k<j;k++)
{
 print
"line",nodelon[seg_start[k]],nodelat[seg_start[k]],nodelon[seg_end[k]],nodelat[seg_end[k]]
>>"planet.mif"
 print seg[k] >> "planet.mid"
}
}' planet.osm


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Lars Aronsson
Johnny Doe wrote:

> The easiest way to import the planet.osm into Qgis is
> to convert it into mapinfo format. It is very simple
> and does not require any bizarre tools.

I think the 2nd edition of O'Reilly's book "Mapping Hacks" with
the sticker "now covers Open Street Map" has the potential of
being twice as thick as the 1st edition.  Should we start to
collect these "Open Street Mapping Hacks" on the wiki?  One page
for each recipe, just like a cookbook.


--
  Lars Aronsson ([hidden email])
  Aronsson Datateknik - http://aronsson.se

_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Jo Walsh
On Sat, Apr 15, 2006 at 05:30:37PM +0200, Lars Aronsson wrote:
> > The easiest way to import the planet.osm into Qgis is
> > to convert it into mapinfo format.
>
> I think the 2nd edition of O'Reilly's book "Mapping Hacks" with
> the sticker "now covers Open Street Map" has the potential of
> being twice as thick as the 1st edition.  Should we start to
> collect these "Open Street Mapping Hacks" on the wiki?  One page
> for each recipe, just like a cookbook.

An OSM cookbook sounds like a wonderful idea. There are print on
demand setups you could think about putting it through, if you wanted
to get carried away. http://wndw.net/ is a good technical book done
this way. I don't think it's that likely there will be a second
edition of "Mapping Hacks". And so much would need to be changed,
since summer 2004, it would be at least half a completely different book.


jo





_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Johnny Doe-2
In reply to this post by Johnny Doe-2

Here is the corrected and tested version of the script
that creates two layers - nodes and segments.
Lars, you can also try to run
ogr2ogr -f "esri shapefile" -spat 7 55 20 62
nodes_sverige.shp nodes.mif
ogr2ogr -f "esri shapefile" -spat 7 55 20 62
segments_sverige.shp segments.mif
qgis nodes_sverige.shp segments_sverige.shp
and feel the rendering speed :)

---
awk -F\" 'BEGIN{
 i=-1;j=-1;
 system("rm -f planet.mi? nodes.mi? segments.mi?");
printf("version 300\ncharset \"utf-8\"\n\
coordsys earth projection 1, 104\n\
delimiter \",\"\n\
columns 1\n\
cat integer\n\
data\n\n") >"planet.mif";
 system("cp planet.mif nodes.mif; cp planet.mif
segments.mif");
}
{
        if ($1 == "  <node id=")
         {
          nodes[i++]=$2; nodelat[$2]=$4;
          nodelon[$2]=$6;
         }
        if ($1 == "  <segment id=")
         {
          seg[j++]=$2; seg_start[j]=$4;
          seg_end[j]=$6;
         }
}
END{
for(k=0;k<i;k++)
{
 print "point",nodelon[nodes[k]],nodelat[nodes[k]] >>
"planet.mif"
 print nodes[k] >> "planet.mid"
}
system("cp planet.mif nodes.mif; cp planet.mid
nodes.mid");
for(k=0;k<j;k++)
{
 print
"line",nodelon[seg_start[k]],nodelat[seg_start[k]],nodelon[seg_end[k]],nodelat[seg_end[k]]
>>"planet.mif"
 print seg[k] >> "planet.mid"
 print
"line",nodelon[seg_start[k]],nodelat[seg_start[k]],nodelon[seg_end[k]],nodelat[seg_end[k]]
>>"segments.mif"
 print seg[k] >> "segments.mid"
}
system("rm -f nodes.shp nodes.shx nodes.dbf nodes.prj;
ogr2ogr -f \"esri shapefile\" nodes.shp nodes.mif");
system("rm -f segments.shp segments.shx segments.dbf
segments.prj; ogr2ogr -f \"esri shapefile\"
segments.shp segments.mif");
}' planet.osm

---


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Richard Fairhurst
In reply to this post by Jo Walsh
Quoting Jo Walsh <[hidden email]>:

> An OSM cookbook sounds like a wonderful idea.

Thirded.

Richard


_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk
Reply | Threaded
Open this post in threaded view
|

Re: Using OSM with PostGIS

Joerg Ostertag (OSM Tettnang/Germany)
In reply to this post by Lars Aronsson
On Saturday 15 April 2006 17:30, Lars Aronsson wrote:

> Johnny Doe wrote:
> > The easiest way to import the planet.osm into Qgis is
> > to convert it into mapinfo format. It is very simple
> > and does not require any bizarre tools.
>
> I think the 2nd edition of O'Reilly's book "Mapping Hacks" with
> the sticker "now covers Open Street Map" has the potential of
> being twice as thick as the 1st edition.  Should we start to
> collect these "Open Street Mapping Hacks" on the wiki?  One page
> for each recipe, just like a cookbook.

Sounds like a great Idea to have many coding examples to handle the OSM Data!

--
http://www.ostertag.name/

_______________________________________________
talk mailing list
[hidden email]
http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/talk