Combining shp-Files and csv-Data

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

Combining shp-Files and csv-Data

kamallauber
Hey people,

first of all:I am Using R 2.15.3.
I have 2 shapefiles (.shp+.dfb+...) and a csv-table.
Now, one shape(1) is the border of germany and the other is a grid-like shapefile (2) (not a grid but many little cubes (1x1km). Now I want to have a grid-like shapefile but only in the boundaries of the first shapefile.
Both of them are spatialpolygondataframes.

The next step would then be, to get the values from the csv-table to the in the attribute table of the shapefile. The csv has a certain column 'cellnumber' which corresponds to a column in the grid-like shapefile (2).

I know that this can easily be done with other gis software such as arcgis but i need to do it with R.
Any help would be much appreciated.

Greets, Matthias
Reply | Threaded
Open this post in threaded view
|

Re: Combining shp-Files and csv-Data

Roman Luštrik
I would approach this by reading the data in using readOGR from rgdal
package. Once you get your projections in order, I would use one of the
functions in rgeos to find which "cubes" (let's call them squares for the
lack of a better term :) ) lie on the country border.
You can merge() your data from the "overlaid" object with your csv file by
cellnumbers.

HTH,
Roman



On Tue, Apr 9, 2013 at 3:26 PM, kamallauber <[hidden email]> wrote:

> Hey people,
>
> first of all:I am Using R 2.15.3.
> I have 2 shapefiles (.shp+.dfb+...) and a csv-table.
> Now, one shape(1) is the border of germany and the other is a grid-like
> shapefile (2) (not a grid but many little cubes (1x1km). Now I want to have
> a grid-like shapefile but only in the boundaries of the first shapefile.
> Both of them are spatialpolygondataframes.
>
> The next step would then be, to get the values from the csv-table to the in
> the attribute table of the shapefile. The csv has a certain column
> 'cellnumber' which corresponds to a column in the grid-like shapefile (2).
>
> I know that this can easily be done with other gis software such as arcgis
> but i need to do it with R.
> Any help would be much appreciated.
>
> Greets, Matthias
>
>
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Combining-shp-Files-and-csv-Data-tp7583245.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



--
In God we trust, all others bring data.

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Combining shp-Files and csv-Data

kamallauber
First of all thank you for the quick response.

I did read the shapefiles with readOGR and i understand how you would do that with rgeos, but i have a single shapefile which consists of all these little "cubes" and i do not understand in which way i can extract some of these cubes from a single shape file.

Best regards,
Matthias