[gdal-dev] ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

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

[gdal-dev] ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

Simon Eves
Dear List,

I need to do this super-urgently

I am trying to use ogr2ogr -explodecollections but it does nothing.

I don't seem to be able to install GDAL for Python (it fails to compile the wrapper)

I will write a command-line tool in C++ if I have to, but I'd really rather not.

Anyone have the magic incantation, please?

Simon

--

Simon Eves
Senior Graphics Engineer, Rendering Group
100 Montgomery St (5th Floor), San Francisco, CA 94104, USA


Email: [hidden email] | Cell: 415.902.1996



_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

Alan Snow
You could try geopandas. It has an explode method that looks like it does what you want. https://github.com/geopandas/geopandas/blob/a3170ecbf76fc91188cd67c93c123c5fa27e9c95/geopandas/geodataframe.py#L659

On Thu, Oct 10, 2019, 6:17 PM Simon Eves <[hidden email]> wrote:
Dear List,

I need to do this super-urgently

I am trying to use ogr2ogr -explodecollections but it does nothing.

I don't seem to be able to install GDAL for Python (it fails to compile the wrapper)

I will write a command-line tool in C++ if I have to, but I'd really rather not.

Anyone have the magic incantation, please?

Simon

--

Simon Eves
Senior Graphics Engineer, Rendering Group
100 Montgomery St (5th Floor), San Francisco, CA 94104, USA


Email: [hidden email] | Cell: 415.902.1996


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

jratike80
In reply to this post by Simon Eves
Hi,

Please provide some test data and explain in details what did you try.
Spending some time for making an answerable question would certainly be the
best way for getting fast and usable help.

-Jukka Rahkonen-



Simon Eves wrote

> Dear List,
>
> I need to do this super-urgently
>
> I am trying to use ogr2ogr -explodecollections but it does nothing.
>
> I don't seem to be able to install GDAL for Python (it fails to compile
> the
> wrapper)
>
> I will write a command-line tool in C++ if I have to, but I'd really
> rather
> not.
>
> Anyone have the magic incantation, please?
>
> Simon
>
> --
> &lt;http://www.omnisci.com/&gt;
> Simon Eves
> Senior Graphics Engineer, Rendering Group
> 100 Montgomery St (5th Floor), San Francisco, CA 94104, USA
>
>
> Email:

> simon.eves@

>  | Cell:  415.902.1996
>
> _______________________________________________
> gdal-dev mailing list

> gdal-dev@.osgeo

> https://lists.osgeo.org/mailman/listinfo/gdal-dev





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

jratike80
Here is a partial solution or workaround

Take this as input

id,wkt
1,"MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"

Run this
ogr2ogr -f csv -lco geometry=as_wkt -explodecollections wkt_expl.csv wkt.csv

Get this result

WKT,id,wkt
"POLYGON ((296 643,623 660,531 484,349 507,296 643))","1","MULTIPOLYGON (((
296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681 635, 895 588, 632
432, 681 635 )))"
"POLYGON ((681 635,895 588,632 432,681 635))","1","MULTIPOLYGON ((( 296 643,
623 660, 531 484, 349 507, 296 643 )), (( 681 635, 895 588, 632 432, 681 635
)))"

So, the original multigeometry is included in both lines but an additional
WKT columns contains the exploded polygons. Without -lco geometry=as_wkt
just the the multipolygon geometry is written into both lines.

id,wkt
"1","MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"
"1","MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"


So something happened but not exactly what I would have guessed. Use case is
a bit special but perhaps this is buggy behavior.

-Jukka Rahkonen-



jratike80 wrote
> Hi,
>
> Please provide some test data and explain in details what did you try.
> Spending some time for making an answerable question would certainly be
> the
> best way for getting fast and usable help.
>
> -Jukka Rahkonen-





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr to convert one CSV row of MULTIPOLYGON to many CSV rows of POLYGON

Simon Eves
Thanks for that, Jukka, and sorry for the vagueness of my original post... I was under a very tight deadline to finish something on Thursday before being away for a long weekend.

I got the same result as you without the -lco option. The output file just contained the same MULTIPOLYGONS, although the file was not identical (I presume due to precision of some of the numbers).

Adding that option, however, still doesn't create a third column, at least not with my file, which I also neglected to say is very wide (hundreds of thousands of small POLYGONs in each MULTIPOLYGON).

The file is private data, so I can't post it, I'm afraid.

In the end, I wrote a script to just read in the file as text and chop up the lines, basically splitting on ")),((".

I'll have a play with geopandas too.

SE


On Fri, Oct 11, 2019 at 6:09 AM jratike80 <[hidden email]> wrote:
Here is a partial solution or workaround

Take this as input

id,wkt
1,"MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"

Run this
ogr2ogr -f csv -lco geometry=as_wkt -explodecollections wkt_expl.csv wkt.csv

Get this result

WKT,id,wkt
"POLYGON ((296 643,623 660,531 484,349 507,296 643))","1","MULTIPOLYGON (((
296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681 635, 895 588, 632
432, 681 635 )))"
"POLYGON ((681 635,895 588,632 432,681 635))","1","MULTIPOLYGON ((( 296 643,
623 660, 531 484, 349 507, 296 643 )), (( 681 635, 895 588, 632 432, 681 635
)))"

So, the original multigeometry is included in both lines but an additional
WKT columns contains the exploded polygons. Without -lco geometry=as_wkt
just the the multipolygon geometry is written into both lines.

id,wkt
"1","MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"
"1","MULTIPOLYGON ((( 296 643, 623 660, 531 484, 349 507, 296 643 )), (( 681
635, 895 588, 632 432, 681 635 )))"


So something happened but not exactly what I would have guessed. Use case is
a bit special but perhaps this is buggy behavior.

-Jukka Rahkonen-



jratike80 wrote
> Hi,
>
> Please provide some test data and explain in details what did you try.
> Spending some time for making an answerable question would certainly be
> the
> best way for getting fast and usable help.
>
> -Jukka Rahkonen-





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--

Simon Eves
Senior Graphics Engineer, Rendering Group
100 Montgomery St (5th Floor), San Francisco, CA 94104, USA


Email: [hidden email] | Cell: 415.902.1996



_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev