Re: Clipping 60 shape layers

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

Re: Clipping 60 shape layers

Koos Hagg
Hi All,
have been searching around for the answer to this question, and found an old thread on this list.

I have a folder which contains about 30 shapefiles, old (but still useful) vmap0 data, but it is 500mb in size. I'd like to clip each shapefile to just the region I need.
I understand about ogr2ogr, and I could do it one by one,

but I would like to figure out how to write a batch file to do it all at once. However- I have been trying this and that for a while, not making any progress.

any help is appreciated!


Koos



Date: Thu, 15 Mar 2012 19:59:44 +0200
From: Zirneklitis <[hidden email]>
Subject: Re: [Qgis-user] Clipping 60 shape layers
To: [hidden email]

Use ogr2ogr:

ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp output.shp input.shp

Karlis

Bis Nulama wrote:
> ..
> I have 60 shape layers and I would like to cut them on a poligon shape
> (region boundary).
> Is there a way to do this selecting all the 60 layers at once (and not
> repeating the clip command 60 times)?
> ..
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Clipping 60 shape layers

Salvatore Larosa-2
Il giorno lun, 07/05/2012 alle 19.56 +0700, Koos Hagg ha scritto:

> Hi All,
> have been searching around for the answer to this question, and found
> an old thread on this list.
>
> I have a folder which contains about 30 shapefiles, old (but still
> useful) vmap0 data, but it is 500mb in size. I'd like to clip each
> shapefile to just the region I need.
> I understand about ogr2ogr, and I could do it one by one,
>
> but I would like to figure out how to write a batch file to do it all
> at once. However- I have been trying this and that for a while, not
> making any progress.
>
> any help is appreciated!
>
Hi Koos,
I didn't test it!

#!/bin/bash
i=1;
for f in *.shp; do
ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp `basename
$f .shp`_out_[$i].shp $f;
i=$((i+1));
done;
>
Hope this helps!

Regards,

-SL


--
Salvatore Larosa
linkedIn: http://linkedin.com/in/larosasalvatore
twitter: @lrssvt
skype: s.larosa
IRC: lrssvt

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

Re: Clipping 60 shape layers

Etienne Tourigny-3
better yet something like

for f in *.shp; do
  ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp `basename $f .shp`_clip.shp $f;
done;

On Mon, May 7, 2012 at 10:51 AM, Salvatore Larosa <[hidden email]> wrote:

> Il giorno lun, 07/05/2012 alle 19.56 +0700, Koos Hagg ha scritto:
>> Hi All,
>> have been searching around for the answer to this question, and found
>> an old thread on this list.
>>
>> I have a folder which contains about 30 shapefiles, old (but still
>> useful) vmap0 data, but it is 500mb in size. I'd like to clip each
>> shapefile to just the region I need.
>> I understand about ogr2ogr, and I could do it one by one,
>>
>> but I would like to figure out how to write a batch file to do it all
>> at once. However- I have been trying this and that for a while, not
>> making any progress.
>>
>> any help is appreciated!
>>
> Hi Koos,
> I didn't test it!
>
> #!/bin/bash
> i=1;
> for f in *.shp; do
> ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp `basename
> $f .shp`_out_[$i].shp $f;
> i=$((i+1));
> done;
>>
> Hope this helps!
>
> Regards,
>
> -SL
>
>
> --
> Salvatore Larosa
> linkedIn: http://linkedin.com/in/larosasalvatore
> twitter: @lrssvt
> skype: s.larosa
> IRC: lrssvt
>
> _______________________________________________
> Qgis-user mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Clipping 60 shape layers

dbnakuru
In reply to this post by Koos Hagg
I do this a lot.  If both the input and the output arguments to ogr2ogr are directories then it will clip all of the shapes in the source directory and write them to the output directory.  In my case I let it create the output directory but it mi9ght work to write to an existing directory.  I use linux by the way so I don't know if it works this way on Windows or Mac.

So: ogr2ogr -clipsrc mask.shp output source

Shapefiles are the default so you don't even need the -f "ESRI Shapefile".

Koos Hagg wrote:
Hi All,
have been searching around for the answer to this question, and found an old thread on this list.

I have a folder which contains about 30 shapefiles, old (but still useful) vmap0 data, but it is 500mb in size. I'd like to clip each shapefile to just the region I need.
I understand about ogr2ogr, and I could do it one by one,

but I would like to figure out how to write a batch file to do it all at once. However- I have been trying this and that for a while, not making any progress.

any help is appreciated!


Koos



Date: Thu, 15 Mar 2012 19:59:44 +0200
From: Zirneklitis <[hidden email]>
Subject: Re: [Qgis-user] Clipping 60 shape layers
To: [hidden email]

Use ogr2ogr:

ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp output.shp input.shp

Karlis

Bis Nulama wrote:
> ..
> I have 60 shape layers and I would like to cut them on a poligon shape
> (region boundary).
> Is there a way to do this selecting all the 60 layers at once (and not
> repeating the clip command 60 times)?
> ..
_______________________________________________ Qgis-user mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/qgis-user


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

Clipping 60 shape layers

Koos Hagg
Thank you all!

The tip that you can specify a folder (not only individual files) in the ogr2ogr command was the breakthrough. That helps a lot, and will make other tasks like this a breeze, now that I know this. :)

-happy mapping,
Koos



On Tue, May 8, 2012 at 12:16 AM, David J. Bakeman <[hidden email]> wrote:
I do this a lot.  If both the input and the output arguments to ogr2ogr are directories then it will clip all of the shapes in the source directory and write them to the output directory.  In my case I let it create the output directory but it mi9ght work to write to an existing directory.  I use linux by the way so I don't know if it works this way on Windows or Mac.

So: ogr2ogr -clipsrc mask.shp output source

Shapefiles are the default so you don't even need the -f "ESRI Shapefile".

Koos Hagg wrote:
Hi All,
have been searching around for the answer to this question, and found an old thread on this list.

I have a folder which contains about 30 shapefiles, old (but still useful) vmap0 data, but it is 500mb in size. I'd like to clip each shapefile to just the region I need.
I understand about ogr2ogr, and I could do it one by one,

but I would like to figure out how to write a batch file to do it all at once. However- I have been trying this and that for a while, not making any progress.

any help is appreciated!


Koos



Date: Thu, 15 Mar 2012 19:59:44 +0200
From: Zirneklitis <[hidden email]>
Subject: Re: [Qgis-user] Clipping 60 shape layers
To: [hidden email]

Use ogr2ogr:

ogr2ogr -f "ESRI Shapefile" -clipsrc mask.shp output.shp input.shp

Karlis

Bis Nulama wrote:
> ..
> I have 60 shape layers and I would like to cut them on a poligon shape
> (region boundary).
> Is there a way to do this selecting all the 60 layers at once (and not
> repeating the clip command 60 times)?
> ..
_______________________________________________ Qgis-user mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/qgis-user




_______________________________________________
Qgis-user mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/qgis-user