[osmosis-dev] Invalid ways, now with code

Paweł Paprota ppawel at fastmail.fm
Thu Dec 13 11:13:44 GMT 2012


On 12/13/2012 03:48 AM, Toby Murray wrote:
>>
>> SELECT ST_IsValid('LINESTRING(1 1, 1 1, 1 1, 1 1, 1 1)'::geometry)
>
> This was touched on in the previous thread a little. The problem is
> that there is no direct interaction with the database at this level.
> When doing an import, no connection to the database even exists.
> Everything goes to a dump file and is then loaded in via a COPY
> command. So I can't just call ST_IsValid.

Sure, I didn't mean that you should call ST_IsValid - it was just to 
illustrate the point that a way with 5 nodes that are in the same 
position is invalid.

> Furthermore, I don't see a
> way of checking for geometry validity in java.

GEOS (which PostGIS is based on) is a port of JTS from Java to C so 
there most certainly is a way to check validity in Java :-)

http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#isValid()

The implementation does not seem too complicated, it could be used in 
Osmosis...

https://github.com/sergei/jts/blob/master/src/com/vividsolutions/jts/operation/valid/IsValidOp.java#L185

> Also, out of the 3,455 ways with invalid geometries currently in my
> database, 3,157 of them are single node ways. So just this simple node
> count check eliminates over 90% of invalid geometries. Given the
> challenges and costs of doing more exhaustive checking, this seems
> like a decent compromise.
>

Sure but in this case I would suggest naming this option differently 
because setting keepInvalidWays to false implies that there will be no 
invalid ways in the database which may not be true with the current 
implementation of this option.

> I don't think it is currently possible to keep *all*
> invalid ways out of the database during an import. If this is really a
> requirement, it will need to be done with a query after the database
> has been populated.
>

I'm not sure about this - WayGeometryBuilder#createWayLinestring seems 
like a perfect place to plug in the code from JTS to skip invalid ways.

Paweł




More information about the osmosis-dev mailing list