1

Excuse my first question being slightly more Numpy and less actual GIS, but it relates to latitude / longitude so I thought I'd give it a shot.

Problem: I have a flat file with latitude and longitude and I'm asked to increase the resolution of these individual points.

Currently I'm given a flat file with latitude/longitude and I'm asked to change the 0.001 resolution (~100m resolution) point grid and create 8 more points turning it into .00025 res (~30m resolution) grid. Example of the XX.XXX reoslution points below:

HUC4,Longitude,Latitude
1204,-95.956,30.05
1204,-95.955,30.048

Now I believe this is the basis of pretty much all interpolation on rasters and such, as well as slope and other cell calculations. I have created the very un-pythonic solution for myself:

#Input
csvinput = open(file, 'r')
reader = csv.DictReader(csvinput, delimiter=',')
#Output
dst_file = open("out.csv",'wt')
dst_file.write( "longitude,latitude,huc4\n" )
lformat = '%.5f,%.5f,%5s'

for row in reader:
    huc4 = row['HUC4']
    # Longitude Value
    x = float(row["Longitude"])
    xup = x + newres
    xdwn = x - newres
    # Latitude values
    y = float(row["Latitude"])
    yup = y + newres
    ydwn = y - newres
'''
###################################################
# Make sure we create the new matrix properly
###################################################
###################################################
xup  ,ydwn | xup, y  | xup , yup
x    ,ydwn |  x,  y  | x   , yup
xdwn ,ydwn | xdwn,y  | xdwn, yup
###################################################
###################################################
'''
    line = (lformat % (float(x),float(y), str(huc4))) + '\n'
    dst_file.write( line )
    # X Upper Axis
    line = (lformat % (float(xup),float(y), str(huc4))) + '\n'
    dst_file.write( line )
    line = (lformat % (float(xup),float(ydwn), str(huc4))) + '\n'
    dst_file.write( line )
    line = (lformat % (float(xup),float(yup), str(huc4))) + '\n'
    dst_file.write( line )
    # X Middle Axis
    line = (lformat % (float(x),float(yup), str(huc4))) + '\n'
    dst_file.write( line )
    line = (lformat % (float(x),float(ydwn), str(huc4))) + '\n'
    dst_file.write( line )
    # X Lower Axis 
    line = (lformat % (float(xdwn),float(ydwn), str(huc4))) + '\n'
    dst_file.write( line )
    line = (lformat % (float(xdwn),float(y), str(huc4))) + '\n'
    dst_file.write( line )
    line = (lformat % (float(xdwn),float(yup), str(huc4))) + '\n'
    dst_file.write( line )

Now I am very new to python and I know that there are many ways to enhance this as well as storage, but for my purpose, my colleagues see flat files as easiest right now (though I have been messing with Postgres). Any tips on that end would not fall on deaf ears, but my main concern is the creation of the new points.

Can anyone expand on the type of numpy array algorithm you would use?

Can I just create a master array for x and a master array for y and then combine the two together (sorta like a pandas dataframe?):

longarray = [xup, x, xdwn, xup, x, xdwn, xup, x, xdwn]
latarray = [ydwn, ydwn, ydwn, y, y, y, yup, yup, yup]
  • This looks like it would be a better fit for a code review site. Raster resampling is a pretty basic part on any GIS -- why do you need to reinvent this wheel? – Vince Nov 19 '15 at 19:07
  • I had the same impression but I wanted to make sure my cell centroids were at the resolution of the original grid points, as I know that I can use gdalwarp with -tap, but I'm not versed enough to get a rounded, 4 digit centroid and I fear that I might round/miss a value – hydro_logic Nov 19 '15 at 19:23
  • Yes, but that question would be appropriate here, while Python code review is not. – Vince Nov 20 '15 at 1:55
  • fair enough, thanks for the correction, i'll reword it! – hydro_logic Nov 23 '15 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.