0

I have a historical temperature and precipitation observations in each individual txt file for the globe by year (I have total 35 txt file for yearly temperature/precipitation), and in my research case, I need to study climate trend of Germany from 1980 to 2014 both by using respective temperature and precipitation observation. However, the challenge is, in each txt file where yearly temperature and precipitation observation has been recorded for the globe, the only geographic coordinate of the station and its respective monthly temperature/precipitation observation has been recorded (name of the weather stations are not provided).

My question is, I need to interpolate all temperature and precipitation observation of yearly data record of only German weather station to its respective NUT3 level (by district, Germany has 403 small districts) polygon and run possible regression model (to find out meaningful trend that how weather has been/ would have been affecting to Germany' agriculture and its economy). But, I need to extract out all rows or observation from each txt file where its geographic coordinate (longitude/latitude) belongs to Germany territory. I don't know how to deal with those geographic coordinates and which are belong to German territory.

How can I make this happen in R?

After I could extract right geographic coordinate of weather station which is truly lie in German territory, I could interpolate them by using ArcGis software.

for example, here is how head of each txt file where yearly temperature observation has been recorded by globe (global temperature observation in 1980):

Longitude   Latitude    Jan.    Feb.    Mar.    Apr.    May June    July    Aug.    Sept.   Oct.    Nov.    Dec.
-179.75 68.75   -27 -28.2   -27.2   -21.6   -9  0.6 2.8 1.9 -0.2    -11.9   -22.7   -25.1
-179.75 68.25   -27.8   -28.5   -27.5   -22 -9.5    0.4 3   1.8 -0.8    -12.7   -23.6   -26.8
-179.75 67.75   -26.8   -26.6   -25.7   -20.5   -8  2.7 6   4   0.5 -12.2   -23.2   -27.3
-179.75 67.25   -29.1   -28.4   -27.5   -22.3   -9.7    2.2 6.2 3.3 -1.3    -15.4   -26.4   -31.1
-179.75 66.75   -25.4   -23.8   -22.9   -18.2   -6.1    3.8 8.6 6   1.1 -11.5   -22.3   -27.2
-179.75 66.25   -21.5   -18.9   -17.2   -14 -2.3    3.4 9.2 7.2 2.2 -7.1    -17.5   -22.6
-179.75 65.75   -20.2   -17.9   -17.1   -13.2   -2.2    4.3 10.1    8.9 3.8 -6  -17.8   -21.4

And here is how head of each txt file where yearly precipitation observation has been recorded by globe (global precipitation observation in 1980):

Longitude   Latitude    Jan.    Feb.    Mar.    Apr.    May June    July    Aug.    Sept.   Oct.    Nov.    Dec.
-179.75 68.75   24.6    25  11.7    13.1    12  6.5 20.8    40.3    0.1 16.5    22.4    9.3
-179.75 68.25   26.9    28.9    10.8    11.7    11.1    7.3 30.9    34.4    2.5 19.3    24.2    9
-179.75 67.75   30.5    40  10.8    10.8    10.9    8.7 46.7    27.4    3.6 23.3    28.2    9.7
-179.75 67.25   36.5    53  11.6    11.3    11.6    11  59  23  4.6 28.1    33.1    11.9
-179.75 66.75   33.4    50.5    9.3 7.2 8.8 10.9    70  20.7    3.5 20.7    25.8    12.6
-179.75 66.25   25.4    40.7    5.5 1.8 3.4 10.1    76.6    17.8    1.9 6.5 11.2    13.8
-179.75 65.75   23.3    43.3    10  1.7 4.7 10.3    65.4    18.2    0.5 7.9 14.4    12.3

and above give data is not german data, in each txt file, yearly temperature observation of all the globe.

You could generate reproducible data by using the code down below:

read.delim2(text='paste above data', sep = ";", header = TRUE)

I want to run data cleaning operation in each txt file for yearly temperature/precipitation observation by globe has been listed. I intend to keep the row in each txt file where respective geographic coordinate belongs to German territory. And I would like to run my operation programmatically where accessing a list of all txt files for yearly Temp/Precipitation observation (where ) by global (in each folder (data for Temperature/ Precipitation), which has 35 txt file that needs to programmatically edit).

I need to extract all geographic coordinates which belong only belongs to Germany from each txt file then use ArcGis to do interpolation.

closed as off-topic by BERA, whyzar, aldo_tapia, PolyGeo Mar 28 '18 at 22:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – BERA, whyzar, aldo_tapia, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I would ask a separate question about interpolation once you get the data in a spatial format for all of Germany. You may also want to do some research on various interpolation methods since weather station interpolation is rather contentious. – GISKid Mar 28 '18 at 21:02
  • 1
    Welcome to GIS SE! As a new user be sure to take the Tour. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. – PolyGeo Mar 28 '18 at 22:24
4

I don't think any of the data you provided actually are in Germany so I made some fake data:

library(rgeos)
library(maptools)
library(sp)
#Get countries
data(wrld_simpl)
plot(wrld_simpl)
#Subset to get Germany only
germany<- wrld_simpl[wrld_simpl@data$NAME =="Germany",]
plot(germany)

#fake station data
stations<-data.frame(Longitude=c(-179.75, -179.75,-85,8,8,8), Latitude=c(68.75,65.75,20,48,55,50))
stations
#This specifies these are the lon and lat
xy<-stations[,c(1,2)]
#make sure in same datum /projection
co<-proj4string(germany)
#create a spatial points data frame from the stations data using the same coordinate system as Germany
stations<-SpatialPointsDataFrame(coords = xy, stations, proj4string = CRS(co))
#visualize where the points fall in the world
plot(wrld_simpl)
plot(stations,col='red', add=TRUE)
#visualize where points fall around germany
plot(germany)
plot(stations, col='red', add=TRUE)

#Get points that fall into germany
ger_pts<- stations[germany,]
plot(germany)
plot(ger_pts, add=TRUE)
  • So given a table of coordinates all over the world, this code will subset the ones that fall within the germany boundary. The plots are only for your own visualization so you can see what's happening. Interpolation is a whole other question. If you can edit your question to what results you get from my code and how it doesn't work I can elaborate further. – GISKid Mar 28 '18 at 23:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.