[gdal-dev] Dissolve shapefile using GDAL/OGR

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

[gdal-dev] Dissolve shapefile using GDAL/OGR

hbobenicio
Hi!

So, My question is pretty simple.
I'm developing a software in C++ that uses GDAL/OGR library to handle geoprocessing computations. What I need to do now is to dissolve a shapefile by a column (similiar to the Quantum GIS tool "Vector > Geoprocessing Tools > Dissolve").
Does GDAL/OGR already support this operation (or eases this somehow)? Do I have to implement it by myself? Do I need to use another library to easily acomplish this task? (GRASS?).

Thanks in advance,
Hugo Benício.

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

Re: Dissolve shapefile using GDAL/OGR

Andreas Oxenstierna
I would use PostGIS - they have comprehensive, very efficient and in my experience 100 % correct set of spatial processing tools.

Hi!

So, My question is pretty simple.
I'm developing a software in C++ that uses GDAL/OGR library to handle geoprocessing computations. What I need to do now is to dissolve a shapefile by a column (similiar to the Quantum GIS tool "Vector > Geoprocessing Tools > Dissolve").
Does GDAL/OGR already support this operation (or eases this somehow)? Do I have to implement it by myself? Do I need to use another library to easily acomplish this task? (GRASS?).

Thanks in advance,
Hugo Benício.


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


-- 
Best Regards

Andreas Oxenstierna
T-Kartan Produkt AB
mobile: +46 733 206831
mailto: [hidden email]
http://www.t-kartor.com

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

Re: Dissolve shapefile using GDAL/OGR

Rahkonen Jukka (Tike)
In reply to this post by hbobenicio
Hugo Benicio <hbobenicio <at> gmail.com> writes:

>
> Hi!
> So, My question is pretty simple.
> I'm developing a software in C++ that uses GDAL/OGR library to handle
geoprocessing computations. What I need to do now is to dissolve a shapefile by
a column (similiar to the Quantum GIS tool "Vector > Geoprocessing Tools >
Dissolve").
> Does GDAL/OGR already support this operation (or eases this somehow)? Do I
have to implement it by myself? Do I need to use another library to easily
acomplish this task? (GRASS?).

Sure at least to some extent. The following command is utilising Spatialite SQL
and it is building unions by attribure "YTA". I suppose GDAL needs to be build
with Spatialite and Spatialite with GEOS. I tested with GDAL-dev Windows build
from gisinternals.com.

Test with ogrinfo

C:\GDAL_dev>ogrinfo  union_test.shp -dialect sqlite
-sql "select ST_union(Geometry),YTA from union_test GROUP BY YTA"

Conversion into shapefile

C:\GDAL_dev>ogr2ogr -f "ESRI Shapefile" union.shp union_test.shp -dialect sqlite
-sql "select ST_union(Geometry),YTA from union_test GROUP BY YTA"


-Jukka Rahkonen-


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

Re: Dissolve shapefile using GDAL/OGR

hbobenicio
Andreas Oxenstierna,
Thanks for your answer, I'll take a look on PostGIS to see if it can be useful in my case, but I probably don't need to use a DBMS.

Jukka Rahkonen,
Thanks for your answer.
I've tried that command but I'm probably missing Spatialite. Maybe I need to recompile my GDAL to use it.
That's the output:

ogrinfo WasaReduzidoFinal.shp -dialect sqlite -sql "select ST_union(Geometry), Lan_ID from WasaReduzidoFinal GROUP BY Lan_ID"
INFO: Open of `WasaReduzidoFinal.shp'
      using driver `ESRI Shapefile' successful.
ERROR 1: Undefined function 'ST_union' used.

Peter Halls,
Thanks for your answer.
This is probably what I'm intended to do.
My shapefiles are constructed among a lot of consecutive intersections in a way that polygons would never overlap, so I'm ok with that.

Thank you all for your quick answers!

Best Regards,
Hugo Benício.


On Tue, Feb 26, 2013 at 11:16 AM, Jukka Rahkonen <[hidden email]> wrote:
Hugo Benicio <hbobenicio <at> gmail.com> writes:

>
> Hi!
> So, My question is pretty simple.
> I'm developing a software in C++ that uses GDAL/OGR library to handle
geoprocessing computations. What I need to do now is to dissolve a shapefile by
a column (similiar to the Quantum GIS tool "Vector > Geoprocessing Tools >
Dissolve").
> Does GDAL/OGR already support this operation (or eases this somehow)? Do I
have to implement it by myself? Do I need to use another library to easily
acomplish this task? (GRASS?).

Sure at least to some extent. The following command is utilising Spatialite SQL
and it is building unions by attribure "YTA". I suppose GDAL needs to be build
with Spatialite and Spatialite with GEOS. I tested with GDAL-dev Windows build
from gisinternals.com.

Test with ogrinfo

C:\GDAL_dev>ogrinfo  union_test.shp -dialect sqlite
-sql "select ST_union(Geometry),YTA from union_test GROUP BY YTA"

Conversion into shapefile

C:\GDAL_dev>ogr2ogr -f "ESRI Shapefile" union.shp union_test.shp -dialect sqlite
-sql "select ST_union(Geometry),YTA from union_test GROUP BY YTA"


-Jukka Rahkonen-


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


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

Re: Dissolve shapefile using GDAL/OGR

Dan Strobridge
I'm getting the same ST_Union error as Benicio but I know I have Spatialite (v.3.0.1-2), SQLite (3.7.10-2), and Geos (3.3.8-1) from my OSGeo4W install on Win7.  I also tried using the GUnion function, which appears to have been replaced by ST_Union at 3.0.0.  In fact, none of the spatial operator functions) appear to work.

This is the first time I've tried implementing anything other than a format conversion or a simple select query using ogr.  Could anyone suggest an ogr2ogr command to me that would test whether it's a Spatialite/Geos installation problem or simply a bug?

Thanks,
Dan Strobridge


+ ogr2ogr -append test6.shp poly.gmt --debug on -dialect sqlite -sql select ST_Union(Geometry),zone from poly GROUP BY zone
OGR: OGROpen(poly.gmt/035FC9C0) succeeded as GMT.
Shape: DBF Codepage = LDID/87 for test6.shp
Shape: Treating as encoding 'ISO-8859-1'.
OGR: OGROpen(test6.shp/03615808) succeeded as ESRI Shapefile.
ERROR 1: Undefined function 'ST_Union' used.
Reply | Threaded
Open this post in threaded view
|

Re: Dissolve shapefile using GDAL/OGR

Even Rouault
Le vendredi 19 juillet 2013 17:23:24, Dan Strobridge a écrit :

> I'm getting the same ST_Union error as Benicio but I know I have Spatialite
> (v.3.0.1-2), SQLite (3.7.10-2), and Geos (3.3.8-1) from my OSGeo4W install
> on Win7.  I also tried using the GUnion function, which appears to have
> been replaced by ST_Union at 3.0.0.  In fact, none of the  spatial
> operator functions
> <http://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-sql-3.0.0.html#p14
> > ) appear to work.
>
> This is the first time I've tried implementing anything other than a format
> conversion or a simple select query using ogr.  Could anyone suggest an
> ogr2ogr command to me that would test whether it's a Spatialite/Geos
> installation problem or simply a bug?

Dan,

If http://trac.osgeo.org/osgeo4w/wiki/pkg-gdal is up-to-date, the current
version of GDAL in OSGeo4W would be GDAL 1.9.X. The SQLite dialect is a new
function of GDAL 1.10 ...

A workaround is to translate your shapefile into a temporary spatialite DB, and
then do the conversion to GMT with the SQL query.

Best regards,

Even

--
Geospatial professional services
http://even.rouault.free.fr/services.html
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

RE: [BULK] Re: Dissolve shapefile using GDAL/OGR

Dan Strobridge

Thanks Evan.  I will try the workaround and use it until GDAL 1.10 has been incorporated into OSGeo4W. 

 

Since you’ve brought up the OSGeo4W installer… mine says my gdal library is current (1.9.2-2) bu when I launch the shell I see the following, which suggests an older version is actually getting loaded.  You don’t happen to know how to resolve this, do you?

 

OSGEO4W home is C:\OSGeo4W\

 

                   -={ OSGeo4W Shell Commands }=-

find: unable to access ".exe": The system cannot find the file specified.

find: unable to access ".bat": The system cannot find the file specified.

 

GDAL 1.7.3, released 2010/11/10

 

 

Thanks so much,

Dan

 

 

 

From: Even Rouault [via OSGeo.org] [mailto:[hidden email]]
Sent: Friday, July 19, 2013 2:01 PM
To: Strobridge, Daniel M.
Subject: [BULK] Re: Dissolve shapefile using GDAL/OGR

 

Le vendredi 19 juillet 2013 17:23:24, Dan Strobridge a écrit :


> I'm getting the same ST_Union error as Benicio but I know I have Spatialite
> (v.3.0.1-2), SQLite (3.7.10-2), and Geos (3.3.8-1) from my OSGeo4W install
> on Win7.  I also tried using the GUnion function, which appears to have
> been replaced by ST_Union at 3.0.0.  In fact, none of the  spatial
> operator functions
> <http://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-sql-3.0.0.html#p14
> > ) appear to work.
>
> This is the first time I've tried implementing anything other than a format
> conversion or a simple select query using ogr.  Could anyone suggest an
> ogr2ogr command to me that would test whether it's a Spatialite/Geos
> installation problem or simply a bug?

Dan,

If http://trac.osgeo.org/osgeo4w/wiki/pkg-gdal is up-to-date, the current
version of GDAL in OSGeo4W would be GDAL 1.9.X. The SQLite dialect is a new
function of GDAL 1.10 ...

A workaround is to translate your shapefile into a temporary spatialite DB, and
then do the conversion to GMT with the SQL query.

Best regards,

Even

--
Geospatial professional services
http://even.rouault.free.fr/services.html
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev


If you reply to this email, your message will be added to the discussion below:

http://osgeo-org.1560.x6.nabble.com/gdal-dev-Dissolve-shapefile-using-GDAL-OGR-tp5036930p5067676.html

To unsubscribe from [gdal-dev] Dissolve shapefile using GDAL/OGR, click here.
NAML


CONFIDENTIALITY: This email and attachments may contain information which is confidential and proprietary. Disclosure or use of any such confidential or proprietary information without the written permission of Weston Solutions, Inc. is strictly prohibited. If you received this email in error, please notify the sender by return e-mail and delete this email from your system. Thank you.   ­­  
Reply | Threaded
Open this post in threaded view
|

RE: [BULK] Re: Dissolve shapefile using GDAL/OGR

Dan Strobridge
Sorry, I meant Even (not Evan).  Another workaround I found is the dissolve polygons tool in SAGA (instaled from OSGeo4W).  I found this tool very handy since SAGA has a command line option and this specific tool allows up to three dissolve fields to be specified.  My syntax was:

saga_cmd shapes_polygons "Polygon Dissolve" -POLYGONS=infile.shp -DISSOLVED=outfile.shp -FIELD_1=combo -FIELD_2=zone -FIELD_3=val -DISSOLVE=0

Dan
Reply | Threaded
Open this post in threaded view
|

RE: [BULK] Re: Dissolve shapefile using GDAL/OGR

kalu671
Hello Dan,
I tried to use the syntax and I am getting the error:
"The filename, directory name, or volume label syntax is incorrect."

my syntax is as below:
inFile = "D:\Dir1\Polygons.shp"
outFile = "D:\Dir2\Dissolved_polygons.shp"

dissolve = 'C:\OSGeo4W64\apps\saga\saga_cmd shapes_polygons "Polygon Dissolve" -POLYGONS = ' + inFile + ' -DISSOLVED = ' + outFile + ' -FIELD_1= Value -DISSOLVE= 0'
               
subprocess.call(dissolve, shell=True)

Would you please suggest what did I do wrong?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: [BULK] Re: Dissolve shapefile using GDAL/OGR

kalu671

Hello all,
Does anybody have suggestions on this issue?
I am just interested on dissolving polygons, if there is another way around, too.

thanks

On Jul 11, 2014 9:21 AM, "kalu671" <[hidden email]> wrote:
Hello Dan,
I tried to use the syntax and I am getting the error:
"The filename, directory name, or volume label syntax is incorrect."

my syntax is as below:
inFile = "D:\Dir1\Polygons.shp"
outFile = "D:\Dir2\Dissolved_polygons.shp"

dissolve = 'C:\OSGeo4W64\apps\saga\saga_cmd shapes_polygons "Polygon
Dissolve" -POLYGONS = ' + inFile + ' -DISSOLVED = ' + outFile + ' -FIELD_1=
Value -DISSOLVE= 0'

subprocess.call(dissolve, shell=True)

Would you please suggest what did I do wrong?

Thanks




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/gdal-dev-Dissolve-shapefile-using-GDAL-OGR-tp5036930p5150675.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

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

Re: [BULK] Re: Dissolve shapefile using GDAL/OGR

Mike Toews-2
In reply to this post by kalu671
The path strings are not escaped, so dissolve[13] is '\a' or '\x07'
and not 'a', which makes the path invalid.

For Windows paths, the best practice is to either use forward slashes
(like unix), or use raw escape with r as a string prefix, e.g.

dissolve = r'C:\OSGeo4W64\apps...'

On 12 July 2014 02:21, kalu671 <[hidden email]> wrote:

> Hello Dan,
> I tried to use the syntax and I am getting the error:
> "The filename, directory name, or volume label syntax is incorrect."
>
> my syntax is as below:
> inFile = "D:\Dir1\Polygons.shp"
> outFile = "D:\Dir2\Dissolved_polygons.shp"
>
> dissolve = 'C:\OSGeo4W64\apps\saga\saga_cmd shapes_polygons "Polygon
> Dissolve" -POLYGONS = ' + inFile + ' -DISSOLVED = ' + outFile + ' -FIELD_1=
> Value -DISSOLVE= 0'
>
> subprocess.call(dissolve, shell=True)
>
> Would you please suggest what did I do wrong?
>
> Thanks
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev