Giter VIP home page Giter VIP logo

ogr2osm's Introduction

ogr2osm.py

test-py2 test-py3

A tool for converting ogr-readable files like shapefiles into .osm data

!!! Notice !!!

This version is no longer maintained, do not file new issues or pull requests here. Development will continue here.

Installation

ogr2osm requires gdal with python bindings. Depending on the file formats you want to read you may have to compile it yourself but there should be no issues with shapefiles. On Ubuntu you can run sudo apt-get install -y python-gdal python-lxml to get the software you need.

It also makes use of lxml. Although it should fall back to builtin XML implementations seamlessly these are less likely to be tested and will most likely run much slower.

To install ogr2osm and download the default translations the following command can be used:

git clone --recursive https://github.com/pnorman/ogr2osm

To update

cd ogr2osm
git pull
git submodule update

About

This version of ogr2osm is based on Andrew Guertin's version for UVM which is in turn based on Ivan Ortega's version from the OSM SVN server.

ogr2osm will read any data source that ogr can read and handle reprojection for you. It takes a python file to translate external data source tags into OSM tags, allowing you to use complicated logic. If no translation is specified it will use an identity translation, carrying all tags from the source to the .osm output.

Import Cautions

Anyone planning an import into OpenStreetMap should read and review the import guidelines located on the wiki. When writing your translation file you should look at other examples and carefully consider each external data source tag to see if it should be converted to an OSM tag.

Usage

Usage: ogr2osm.py SRCFILE

Options:
  -h, --help            show this help message and exit
  -t TRANSLATION, --translation=TRANSLATION
						Select the attribute-tags translation method. See the
						translations/ directory for valid values.
  -o OUTPUT, --output=OUTPUT
						Set destination .osm file name and location.
  -e EPSG_CODE, --epsg=EPSG_CODE
						EPSG code of source file. Do not include the 'EPSG:'
						prefix. If specified, overrides projection from source
						metadata if it exists.
  -p PROJ4_STRING, --proj4=PROJ4_STRING
						PROJ.4 string. If specified, overrides projection from
						source metadata if it exists.
  -v, --verbose         
  -d, --debug-tags      Output the tags for every feature parsed.
  -f, --force           Force overwrite of output file.
  --encoding=ENCODING   Encoding of the source file. If specified, overrides
						the default of utf-8
  --significant-digits=SIGNIFICANTDIGITS
						Number of decimal places for coordinates
  --rounding-digits=ROUNDINGDIGITS
						Number of decimal places for rounding
  --no-memory-copy      Do not make an in-memory working copy
  --no-upload-false     Omit upload=false from the completed file to surpress
						JOSM warnings when uploading.
  --never-download      Prevent JOSM from downloading more data to this file.
  --never-upload        Completely disables all upload commands for this file
						in JOSM, rather than merely showing a warning before
						uploading.
  --locked              Prevent any changes to this file in JOSM, such as
						editing or downloading, and also prevents uploads.
						Implies upload="never" and download="never".
  --id=ID               ID to start counting from for the output file.
						Defaults to 0.

ogr2osm's People

Contributors

adamwill avatar darktyger avatar firefishy avatar fuga avatar impiaaa avatar jendrusk avatar jerry73204 avatar mvexel avatar pnorman avatar reidab avatar roelderickx avatar sebastic avatar tpikonen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ogr2osm's Issues

Inconsistent or missing use of addparent.

addparent is not called on new relation members in splitWayInRelation.

It's also not called on the feature-geometry pairs in splitWay (in contrast to parseFeature).

Neither is a serious issue, the opposite connections are readily accessible.

Error when trying to skip an object in translation

The convention is to return None when you want your translation to skip an object. That seems to cause an error in 9c4b6ea:

Merging points
Making list
Checking list
Merging duplicate points in ways
Outputting XML
Traceback (most recent call last):
  File "ogr2osm.py", line 616, in <module>
    output()
  File "ogr2osm.py", line 563, in output
    for (key, value) in featuresmap[node].tags.items():
AttributeError: 'NoneType' object has no attribute 'items'

ImportError: No module named osgeo

Recently I have made an update from macOS Catalina to Big Sur. My current GDAL/ogr2ogr 3.1.3 I am trying to convert a Shapefile to OSM with the following code

./ogr2osm.py -t translations/my_data.py -o my_data.osm -f -v --no-upload-false --never-download --never-upload --verbose data_dir/my_data.shp

Which is returning the following error

Traceback (most recent call last):
  File "./ogr2osm.py", line 51, in <module>
    from osgeo import ogr
ImportError: No module named osgeo

Fails with non-ascii chars

While trying to use ogr2osm witht this shapefile http://people.debian.org/~naoliv/misc/shape-ogr2osm.tar.bz2 I got this:

$ ./ogr2osm.py -p "+proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52" ../SP_USINAS.SHP
running with ElementTree on Python 2.5+
Preparing to convert file '/tmp/d/SP_USINAS.SHP' to '/tmp/d/ogr2osm/SP_USINAS.osm'.
Will use the PROJ.4 string: +proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52
Using default translations
Using default filterLayer
Using default filterFeature
Using default filterTags
Using default filterFeaturePost
Using default preOutputTransform
Parsing data
Merging points
Making list
Checking list
Outputting XML
Traceback (most recent call last):
  File "./ogr2osm.py", line 636, in <module>
    output()
  File "./ogr2osm.py", line 591, in output
1       ./SP_USINAS.DBF 
2       ./SP_USINAS.PRJ 
3       ./SP_USINAS.SBN 
4       ./SP_USINAS.SBX 
5       ./SP_USINAS.SHP
    f.write(etree.tostring(xmlobject))
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1127, in tostring
    ElementTree(element).write(file, encoding, method=method)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 821, in write
    serialize(write, self._root, encoding, qnames, namespaces)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 940, in _serialize_xml
    _serialize_xml(write, e, encoding, qnames, None)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 933, in _serialize_xml
    v = _escape_attrib(v, encoding)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1091, in _escape_attrib
    return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 22: ordinal not in range(128)

Then installed python-lxml but it still fails:

$ ./ogr2osm.py -p "+proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52" ../SP_USINAS.SHP
running with lxml.etree
Preparing to convert file '/tmp/d/SP_USINAS.SHP' to '/tmp/d/ogr2osm/SP_USINAS.osm'.
Will use the PROJ.4 string: +proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52
Using default translations
Using default filterLayer
Using default filterFeature
Using default filterTags
Using default filterFeaturePost
Using default preOutputTransform
Parsing data
Merging points
Making list
Checking list
Outputting XML
Traceback (most recent call last):
  File "./ogr2osm.py", line 636, in <module>
    output()
  File "./ogr2osm.py", line 588, in output
    tag = etree.Element('tag', {'k':key, 'v':value})
  File "lxml.etree.pyx", line 2570, in lxml.etree.Element (src/lxml/lxml.etree.c:52973)
  File "apihelpers.pxi", line 156, in lxml.etree._makeElement (src/lxml/lxml.etree.c:11834)
  File "apihelpers.pxi", line 144, in lxml.etree._makeElement (src/lxml/lxml.etree.c:11709)
  File "apihelpers.pxi", line 299, in lxml.etree._initNodeAttributes (src/lxml/lxml.etree.c:13280)
  File "apihelpers.pxi", line 1369, in lxml.etree._utf8 (src/lxml/lxml.etree.c:22147)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

Fuzzy node matching

Sometimes shapefiles have nodes that are a couple of mm apart and should be turned into shared ways. It would be useful to be able to specify a tolerance for matching nodes for these cases.

utf-8 encoding xml output

Better results are obtained using an explicit utf-8 encoding of tag values:

f.write(etree.tostring(xmlobject, pretty_print=True,encoding='UTF-8'))

add bounding box information

Hi all!
I'm processing shapefiles with org2osm to feed the resulting data to osmosis (to create an android map with the mapfile-writer plugin). I found that I needed to include bounding box information in the XML file to have it processed. I've modified ogr2osm to accept a parameter '--add-bounds', which makes the script add an XML element 'bounds', like

<bounds maxlat="46.432232" maxlon="8.332256" minlat="46.399087" minlon="8.285852"/>

I have a git branch here containing the changes which I'd push to the repo, but I don't have permission. I've attached my new version so you can check if you'd be happy with the changes - rather than doing it the long way by creating a pull request etc., you may find my contribution acceptable and take it in like that. You may use my code freely. I had to change the extension to .txt, since uploading .py files is not supported...
Kay
ogr2osm.txt

processing never finishes on small dataset

Hi,

I'm having a strange issue with ogr2osm. We are using it to prepare the Belgian open address database shapefile for loading into PSQL using OSM toolset in the following manner:

Download of the address list:
https://downloadagiv.blob.core.windows.net/crab-adressenlijst/Shapefile/CRAB_Adressenlijst.zip

It's not too big imho. And this used to work without a glitch a few months ago (it's automated), both the code of ogr2osm and the wrapper script have not changed since then (the data however did of course)

After zip extraction we first use ogr2ogr on it:

/usr/local/bin/ogr2ogr -s_srs EPSG:31370 -t_srs EPSG:4326 CrabAdr_parsed CRAB/Shapefile/CrabAdr.shp -overwrite

that step works, then we use ogr2osm like:

/usr/local/bin/ogr2osm/ogr2osm.py --idfile=ogr2osm.id --positive-id --saveid=ogr2osm.id CrabAdr_parsed/CrabAdr.shp

This keeps on going until we reach this state of the machine:

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
30559 glenn     20   0 15.793g 0.015t  26116 R 100.0 60.7  24:56.03 python 

The machine still has lots of memory available:

KiB Mem : 26754664 total,   789720 free, 16448580 used,  9516364 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  3797372 avail Mem 

the memory growth stops at that point, 1 cpu is 100% busy and it never stops , I left it running for over 18 hours (which is already abnormal as it used to be less than half hour). So it hangs.

I can't seem to strace this process either, I've never seen this error message before when stracing it:

root@grb-db-0:/usr/local/src/grb# strace -fp 26878
strace: Process 26878 attached
strace: [ Process PID=26878 runs in x32 mode. ]

and then it stays silent. I've never seen that x32 mode messages before and I've been around unix for more than 20 years.

CTRL-C works however and shows this :

Traceback (most recent call last):
  File "/usr/local/bin/ogr2osm/ogr2osm.py", line 723, in <module>
    mergePoints()
  File "/usr/local/bin/ogr2osm/ogr2osm.py", line 559, in mergePoints
    parent.replacejwithi(pointsatloc[0], point)
  File "/usr/local/bin/ogr2osm/geom.py", line 65, in replacejwithi
    j.removeparent(self)
  File "/usr/local/bin/ogr2osm/geom.py", line 23, in removeparent
    Geometry.geometries.remove(self)
KeyboardInterrupt

which tells me this happens in mergePoints() function

I also tried using python 3.5 instead of 2.7 , same symptom.

This is part of an automated toolstack using terraform with google cloud to crunch the data, you could reproduce the entire thing building an exact same machine as we are using now with the repository below

https://github.com/gplv2/crab-osm-qa

The bash script that contains this code is here : https://github.com/gplv2/crab-osm-qa/blob/master/helpers/process_source.sh

Could you shed your 2 cents on this issue please ? I've always had success using ogr2osm tool, in fact, in the same script, we parse the open belgian road database as well and this passes fine. It's just the address database that is showing this behavior.

Would love to get some suggestions at this point. Appreciate this a lot. Thank you for your work as well, it's proven to be essential for the Belgian OSM community.

Greetings,

Glenn

lambda invalid syntax on python 3.4

Hello there,

I'm using python 3.4 on Windows with GDAL installed. To be sure of that, I run:

c:\Users\arlindo.pereira\Downloads>python
Python 3.4.0b1 (v3.4.0b1:3405dc9a6afa, Nov 24 2013, 19:18:21) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal
>>> ^Z

Now, when I try to run ogr2osm without no arguments (should only see the readme file) I get this:

c:\Users\arlindo.pereira\Downloads\ogr2osm>python ogr2osm.py
  File "ogr2osm.py", line 320
    reproject = lambda(geometry): None
                      ^
SyntaxError: invalid syntax

Not working with PROJ.4 string

Still with http://people.debian.org/~naoliv/misc/shape-ogr2osm.tar.bz2 it seems that there is a problem when using PROJ.4 strings.
Normal run:

$ ./ogr2osm.py ../SP_USINAS.SHP                                                                           
running with lxml.etree
Preparing to convert file '/tmp/d/SP_USINAS.SHP' to '/tmp/d/ogr2osm/SP_USINAS.osm'.
Will try to detect projection from source metadata, or fall back to EPSG:4326
Using default translations
Using default filterLayer
Using default filterFeature
Using default filterTags
Using default filterFeaturePost
Using default preOutputTransform
Parsing data
Detected projection metadata:
GEOGCS["GCS_South_American_1969",
    DATUM["South_American_Datum_1969",
        SPHEROID["GRS_1967_Modified",6378160.0,298.25]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.0174532925199433]]
Merging points
Making list
Checking list
Outputting XML

With string:

$ ./ogr2osm.py -v -p "+proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52" ../SP_USINAS.SHP
running with lxml.etree
Preparing to convert file '/tmp/d/SP_USINAS.SHP' to '/tmp/d/ogr2osm/SP_USINAS.osm'.
Will use the PROJ.4 string: +proj=utm +zone=23 +south +ellps=GRS67 +towgs84=-66.87,4.37,-38.52
Using default translations
Using default filterLayer
Using default filterFeature
Using default filterTags
Using default filterFeaturePost
Using default preOutputTransform
Parsing data
Merging points
Making list
Checking list
Outputting XML

and the result is very different. Nothing visible with JOSM and only this inside the file:

<?xml version="1.0"?>
<osm version="0.6" upload="false" generator="uvmogr2osm"><node lat="-89.999400039" visible="true" lon="176.260998507" id="-1"><tag k="USINA_ID" v="         37"/><tag k="NOME" v="3 IRMAOS"/><tag k="PROPRIET_R" v="CESP - COMPANHIA ENERG&#201;TICA DE S&#195;O PAULO"/><tag k="LONGITUDE" v="         -51.312800"/><tag k="GEO_ID" v="         37"/><tag k="SITUA__O" v="EM CONSTRU&#199;&#195;O"/><tag k="LATITUDE" v="         -20.680400"/><tag k="POT_NCIA" v="1.292.000 kM"/></node></osm>

Long ways sould be split into no more than 2000-node ways

Some wasy are too long in the source shapefile and Ogr2osm preserves that as it is. During the transformation they sould be split into no more than 2000 node part so that it would be acceptable by the OSM API.

Pushing the limit and splitting it at exactly 2000 nodes mark might represent a problem for users when adding a new node in the way (eg a new crossing etc). This is why OSM Inspector is raising warnings for all ways that are more than 1900 nodes long:

Long ways with more than 1900 nodes are shown in blue. These should probably be split up into smaller parts. The OSM API allows a way to have up to 2000 nodes.

Ogr2osm should thus split at 1900 or slightly lower limit, eg 1800.

Layer awareness in filterTags()

Currently it is not possible to use the current layer in filterTags. This should be added, but in a backwards compatible way

Fails with message free(): invalid pointer

running ogr2osm.py --help displays the help message then reports
free(): invalid pointer
Aborted (core dumped)

Running python 3.8 in Fedora. I believe I have all of the import modules needed.

Switch encoding testcases to KML

Shapefile encodings are difficult to deal with. The default encoding is Latin-1, not UTF-8 and there is no way to detect the encoding from within ogr2osm. The testcases would be more reliable as KML.

See ual@c64ad0a and issue #21

Memory error

Hi Paul,

I try ogr2osm with a large shp file of a country detailed road network and python stops at 'Parsing data' with 'MemoryError'.
The shp file has size: shp is 180MB and dbf is 1.4GB with over 1.1 million records.
I use Python 2.7.3 32bit at Win7 64bit.

I only managed to produce the osm by using the java shp-to-osm https://github.com/iandees/shp-to-osm which produces many osm files having as option the max nodes per osm file.

At http://wiki.openstreetmap.org/wiki/Ogr2osm I read "In March 2010 Ivansanchez was reported to be working on a revamped version of ogr2osm that would be much slower (10x) but would hold all the data in a SQLite database instead of in memory. pnorman's ogr2osm will work on very large files, given enough ram."

Is there actually a version which works with very large files?
What are the file limits of your version or any way to process large files?

Thanks!

python killed

I use 256G memory and 21T free disk space to run 9G a.gdb. After 9 hours running ,It occurs "killed".

How could this happen?What can i do to fix this? Thanks for any help.

Not returning osm file in Mac

I have cloned the project in Mac. write a translation file which is as follows. Note that my shapefile column names are almost identical to osm tags.

def filterTags(attrs):
    if not attrs:
        return
    tags = {}

    if 'name' in attrs:
        tags['name'] = attrs['name'].strip()
    if 'oneway' in attrs:
        tags['oneway'] = attrs['oneway'].strip()
    if 'osm_id' in attrs:
        tags['osm_id'] = attrs['osm_id'].strip()
    if 'fclass' in attrs:
        tags['highway'] = attrs['fclass'].strip()
    if 'ref' in attrs:
        tags['ref'] = attrs['ref'].strip()
    if 'maxspeed' in attrs:
        tags['maxspeed'] = attrs['maxspeed'].strip()
    if 'layer' in attrs:
        tags['layer'] = attrs['layer'].strip()
    if 'bridge' in attrs:
        tags['bridge'] = attrs['bridge'].strip()
    if 'tunnel' in attrs:
        tags['tunnel'] = attrs['tunnel'].strip()
    if 'road_type' in attrs:
        tags['rnh:roadtype'] = attrs['road_type'].strip()
            
    tags['source'] = 'OWN Data'

    return tags

Now I am using the following command but its not returning any output osm file.

./ogr2osm.py -t translations/road_translation.py -o roads.osm -f -v --no-upload-false --never-download --never-upload Road/Road.shp

Where am I doing wrong?

Transfer node id's from shapefile to .osm file

I have been able to convert a custom road network in shapefile format to .osm data. The original shapefile contains a column "source" and a column "target" to indicate the node id's. After the conversion to .osm format however, these node id's appear to have lost. Instead, new node id's have been chronologically numbered in the .osm file (see below). Is there a way to transfer the original node id's from the shapefile to the .osm file?
Screen Shot 2021-02-12 at 15 06 55

Conversion HERE Shapefile > ogr2osm > bz2 > Navit .bin using Maptool

Dear Mr Norman,

I'm on a mission to convert a Shapefile supplied by Nokia HERE (Microsoft) for use in the open source Navit satnav application. Navit have their own Planet Extractor website where users can download OSM derived .bin files for use with Navit. I have also successfully used Maptool to convert both OSM XML and OSM Protobuf files from Geofabrik to the .bin format required by Navit. However the OSM map for Northern Ireland is missing a lot of crucial data, for example most speed limit information etc.

The steps I have taken so far (Lubuntu 16.04.1 LTS 64bit, 8GB Physical + 8GB swapfile) have been as follows:

1: Convert the HERE Shapefile folder to a single .osm file using your ogr2osm utility: SUCCESS
2: Compress .osm file to bz2 as required by Maptool: SUCCESS
3: Convert osm.bz2 file to Navit friendly .bin file using Maptool: FAIL

The message I get is as follows:

peter@peter-desktop:~$ cd ogr2osm
peter@peter-desktop:~/ogr2osm$ bzcat hereni.osm.bz2 | maptool hereni.bin
PROGRESS: Phase 1: reading input data 0:00 0 MB
PROGRESS1: Processed 0 nodes (0 out) 0 ways 0 relations 0 tiles 0:00 0 MB
INFO: Nodes out of sequence (new 4294967293 vs old 4294967294), adding hash
INFO: Ways out of sequence (new -55 vs old -1), adding hash
FATAL: wrong line in input data (does not start with '<'): >

This does not look like a valid OSM file.
Note that maptool can only process OSM files without wrapped or empty lines.
peter@peter-desktop:~/ogr2osm$ "

As I said, I've used Maptool to convert OSM files (osm.bz2) from Geofabrik into the required .bin files without any problems, and they work, but it's not happy with the one I created myself from a HERE shapefile using ogr2osm. The process of using ogr2osm went smoothly without any errors.

Any interpretation of the error message above will be most gratefully received!!!

Regards,

Peter McKinley

Request for duplicated points

It will be possible to add a switch to disable duplicated points removal?
And it will be possible to remove duplicated points only if it have same tags?

Thank you!

unhandled geometry, type: 3003

In trying to reproduce the steps described at this mechanical import proposal page I use this command line, similar to what they reccommend

python ogr2osm.py -v -f 493011_ctr/CTR_493011_pol.shp -e 32633 --no-upload-false

but I get a lot of errors like this

unhandled geometry, type: 3003

and the resulting file is empty

I m on Fedora 27, I installed gdal with dnf and checked out ogr2osm through git

You can gat the shape files I am using here

Translation file locations

the error
error: Could not load translation method '%s'. Translation script must be in your current directory, or in the translations/ subdirectory of your current or ogr2osm.py directory.
does not reflect where we look for translation scripts

Fails to output nodes in close proximity to each other

While trying to translate addresses for Spokane county I found that 2043 nodes were being dropped before making it to the xml. They are all nodes that are very close to one another. It's been confirmed that after moving the points away from each other ogr2osm will output the points normally.
Confirmed with custom translation and default translation.

Source:
spokane_co_addresses.geojson.gz

XML output:
spokane_co_addresses_fake_version.osm.gz

syntax error

File "ogr2osm/ogr2osm.py", line 579
featuresmap = {feature.geometry : feature for feature in features}
^
SyntaxError: invalid syntax

Python version 2.6.6, stable version in debian. The ^ is actually pointing at the "for".

filterTags not returning

If filterTags does not include a return statement, ogr2osm blows up


Traceback (most recent call last):
  File "./ogr2osm.py", line 570, in <module>
    output()
  File "./ogr2osm.py", line 528, in output
    for (key, value) in featuresmap[node].tags.items():
AttributeError: 'NoneType' object has no attribute 'items'

Exception catching

Currently we catch all exceptions during the testing of translation functions. Although this specific case needs changing to avoid exceptions in bug #6 there may be other cases where we are catching all exceptions. exceptions caught should be more limited in scope.

ogr2osm misses some multipolygons in US National Park boundary shapefile

I am trying to make garmin maps for my own use incorporating the park boundaries in

NPS_-_Land_Resources_Division_Boundary_and_Tract_Data_Service-shp.zip,

which can be downloaded at

https://www.nps.gov/subjects/gisandmapping/tools-and-data.htm. For brevity, call the unzipped shapefile "NPS.shp".

This is a single layer shapefile of polygons of national park boundaries (WGS 84 with coordinates in meters, aka, "metres"). Converting to osm with

ogr2osm.py --positive-id -t nps_boundary.py -o nps.osm NPS.shp

some polygons are successfully translated to a tagged relation of untagged ways, but others are rendered as several tagged lines. I have extracted an example of each: Yosemite National Park is correctly rendered, but Sequoia National Park comes out as three tagged lines. Each of the three ends with a point that begins another, like they should in a multipolygon.

I have tried with GDAL 2.4.0 and 3.1.4 and with python 3.7 and 3.9 with the same results. If the problem is with the data, I haven't found it. Yosemite and Sequoia look like the same sort of objects in the shapefile dbf. I don't know how to read shp directly, but I've attached a GML version with the geometry edited out and they look the same there.

I have attached in a single zipfile:
sequoia-yosemite.zip

sequioa-yosemite.{shp,shx,dbf,prj} -- shapefile of just these two features extracted from NPS.shp
sequoia-yosemite.nogeom.gml -- GML version of the sequoia-yosemite.shp with the geometry edited out.
nps_boundary.py -- my translation script
sequoia-yosemite.osm -- the output from "ogr2osm.py --positive-id -t nps_boundary.py -o sequoia-yosemite.osm sequoia-yosemite.shp

Thank very much for any help!

Multipolygon without inner do not assign tags

If Big polygon that contain multiple ways , and inside is not any inner element, return type Multipolygon/Relation but do not apply any tags on multipolygon. tags only on ways. When display it's not correct, Example big river polygon that contains multiple ways but do not has inner element did not display correctly

Esri fileGDB to OSM direction error.

Hello everyone. I have use

python ogr2osm.py /root/PycharmProjects/GDB/aaa.gdb -f -o /root/PycharmProjects/GDB/a.osm"
It present as follow:
running with lxml.etree
Preparing to convert '/root/PycharmProjects/GDB/aaa.gdb' to '/root/PycharmProjects/GDB/a.osm'.
Will try to detect projection from source metadata, or fall back to EPSG:4326
Using default translations
Using default filterLayer
Using default filterFeature
Using default filterTags
Using default filterFeaturePost
Using default preOutputTransform
Parsing data
Detected projection metadata:
GEOGCS["GCS_WGS_1984",
    DATUM["WGS_1984",
        SPHEROID["WGS_84",6378137.0,298.257223563]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.0174532925199433]]
Merging points
Making list
Checking list
Merging duplicate points in ways
Outputting XML

when open in Qgis ,I find the direction is error. Data in aaa.gdb is two cross line ,one is from west to east, the other is from north to south.

test

However,the a.osm reprsent two cross line like this:
screenshot

How can this happen? Thanks for any help.

Can we convert shp zip to OSM?

Hello @roelderickx Thanks for the nice repository.
I have a question.
I have a shp zip file which contains multiple shp files with other files like prj, shx.
Can I convert this zip file to OSM without loosing any information?

Is it possible?
If I can then can you give me some hint such?

Thank you

Making main flow importable

I'm thinking of making a PR to separate the main function into one function for parsing CLI args, and then a main flow function that takes those CLI args as function argument(s). The aim here would be to make that main flow function easily importable to other scripts. I have one such script for PyQGIS that currently calls ogr2osm as a subprocess, and would like to instead import it as a module.

Would such a PR be welcome? It isn't guaranteed that I'll have the time to write this, but I'd like to look into it.

exception while writing idfile

if OPTIONS.saveid: with open(OPTIONS.saveid, 'wb') as ff: ff.write(str(Geometry.elementIdCounter))

if open(...,"wb") then not str(), if str() then "w" and write in textmode

BTW - Nice work :)

Shared borders represented as duplicated ways.

When converting .shp to .osm it happens that the result has some shared borders that are represented as duplicated wasy

JOSM validator reports;

  • warning: Ways with same position (much too many), when duplicated ways only differ in tags, eg a multipolygon inner border (no tag, just a member of multipolygon relation) overlaps with the same simple polygon (with a simple tag) (example: a meadow within a forest multipolygon) yellow in the picture below:
    image
    fixable by reusing the simple tagged way also as a member of multipolygon relation
  • error: Duplicated ways (regular occurance) when both overlapping ways have the same tags, or no tags if they are both members of different relations. (example: outer/exclave meadow within a forest multipolygon or multi-level-multipolygons) red in the picture below:
    image
    fixable by reusing same way (the only one) in both relations
  • warning: Self-intersecting way (some) when it is drawn as such in .shp, probably unrelated
    image
    fixable by reordering nodes within way?

I was using my translation rules:
https://github.com/stefanb/ogr2osm-translations/blob/master/raba-kgz.py
but that is probably irrelevant.

The same problems appears when opening a shapefile directly in JOSM (no ogr2osm involved) due to shapefile structure. Reported an issue 10743

Pass options to translation modules

It would be useful to be able to pass config options to translations modules. This would allow for more generalized translations as well as debug code in translation modules that is later disabled.

Converting DWG files to OSM

Hello everybody,

I am looking fro a way to convert DWG data into OSM XML format inorder to import it later in a project based on the openstreetmap-website project. According to the list stated on this wiki-site, ogr2osm should be able to consume AutoCad DWG data.

When I try to convert a DWG-file with the help of osm2ogr, I get this error:
"OGR failed to open ../path/to/myFile.dwg, format may be unsupported"

Am I missing something? Any help would be more than appreciated!

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.