[R-sig-Geo] How to crop a shapefile ?

Baptiste Coulmont coulmont at gmail.com
Fri Dec 18 09:51:55 CET 2009


Many thanks to everyone !

On Thu, Dec 17, 2009 at 8:47 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Thu, 17 Dec 2009, Dan Putler wrote:
>
>> Hi all,
>>
>> For this particular problem, Dylan Beaudette is probably exactly right.
>> However, I ran into problems using similar tools in OpenJump when we
>> wanted to create a shapefile of a region that we could postal address
>> geocode against (the way the boundary line segments were clipped was a
>> problem for the geocoder), which lead me to write tools in R to do it
>> (outlined in my earlier post). That code does not clip lines, rather it
>> enable the extraction of the original complete road segments. Since most
>> of the ways in OSM don't have the attribute information needed for
>> geocoding, the issue I was addressing won't be relevant here.
>>
>> Besides GRASS (which can be a bit overwhelming at first), and OpenJump
>> (mentioned above), the Clip tool within the fTools plug-in for QGIS
>> should also work. Given the size of the OSM road network files, a
>> machine with a fair amount of memory will probably be needed to handle
>> the problem.
>
> It also looks as though the clipping capabilities of ogr2ogr will increase
> when GDAL 1.7.0 arrives - the beta is already available:
>
> http://www.gdal.org/ogr2ogr.html
> http://download.osgeo.org/gdal/gdal-1.7.0b1.tar.gz
>
> In addition, something like this might be a candidate for rgeos (on R-Forge)
> but would involve C coding in the GEOS C API.
>
> Roger
>
>>
>> Dan
>>
>> On Thu, 2009-12-17 at 10:27 -0800, Dylan Beaudette wrote:
>>>>
>>>> On Thu, 2009-12-17 at 11:07 +0100, Baptiste Coulmont wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I'm working with R and various shapefiles created by the OpenStreetMap
>>>>> project. Those shapefiles (the roads in particular) are quite big.
>>>>>
>>>>> How can I crop (or "trim", or "prune" those objects -- once in a
>>>>> SpatialLineDataFrame -- if I need to work not on a national level but
>>>>> on a municipal level ?
>>>>>
>>>>> Is it possible to create a subset of a smaller zone ?
>>>>> Coordinates:
>>>>>         min       max
>>>>> r1  2.560776  6.403847
>>>>> r2 49.493613 51.505419
>>>>>
>>>>> Thansk,
>>>>> B. Coulmont
>>>
>>> This type of work is most efficiently done in a standard GIS. I would
>>> suggest
>>> installing GRASS GIS or something like that. This is a standard vector
>>> operation, and should be very fast. For this GRASS approach, see the
>>> v.overlay command.
>>>
>>> Cheers,
>>> Dylan
>>>
>>>
>>>
>>
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no
>
>



-- 
Baptiste   Coulmont
http://coulmont.com



More information about the R-sig-Geo mailing list