Changeset 9320
- Timestamp:
- Sep 3, 2014, 3:47:05 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 29 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/shallow_water/swDE1_domain_ext.c
r9318 r9320 2092 2092 2093 2093 double timestep; 2094 int max_flux_update_frequency;2095 2094 2096 2095 if (!PyArg_ParseTuple(args, "Od", &domain, ×tep)) { -
trunk/anuga_core/source/anuga/utilities/quantity_setting_functions.py
r9299 r9320 5 5 """ 6 6 import copy 7 import os 8 import anuga.utilities.spatialInputUtil as su 7 9 8 10 def make_nearestNeighbour_quantity_function(quantity_xyValueIn, domain, threshold_distance = 9.0e+100, background_value = 9.0e+100): … … 79 81 80 82 poly_fun_pairs = [ [p0, f0], [p1, f1], ...] 81 where fi is a function, or a constant, or the name of a gdal-compatible rasterFile; 82 and pi is a polygon, or None, or 'All' (or it can be 'Extent' in the case that fi is a rasterFile name) 83 84 Where: 85 86 fi is a function, or a constant, or the name of a 87 gdal-compatible rasterFile, or a numpy array with 3 columns; 88 89 pi is a polygon, or a polygon filename (shapefile or a csv format that anuga.read_polygon will read), 90 or None, or 'All' (or it can be 'Extent' in the case that fi is a 91 rasterFile name) 83 92 84 93 IMPORTANT: When polygons overlap, the first elements of the list are given priority. … … 101 110 pi are polygons where we want to use fi inside 102 111 SPECIAL pi CASES: 112 If pi is a filename ending in .shp or a csv format that anuga.read_polygon can read, we assume it contains a polygon we have to read 103 113 If any pi = 'All', then we assume that ALL unset points are set 104 114 using the function. This CAN ONLY happen in the last [fi,pi] pair where pi is … … 160 170 # Here fi MUST be a gdal-compatible raster 161 171 # Then we get the extent from the raster itself 162 import anuga.utilities.spatialInputUtil as su163 172 pi_path=su.getRasterExtent(fi,asPolygon=True) 173 elif( type(pi)==str and os.path.isfile(pi) ): 174 # pi is a file 175 pi_path=su.read_polygon(pi) 164 176 else: 177 # pi is the actual polygon data 165 178 pi_path=pi 179 166 180 notSet=(isSet==0.).nonzero()[0] 167 181 fInds = inside_polygon(xy_array_trans[notSet,:], pi_path) -
trunk/anuga_core/source/anuga/utilities/spatialInputUtil.py
r9299 r9320 6 6 readShp_1PolyGeo, readShp_1LineGeo -- read SIMPLE shapefile geometries into ANUGA as a list of points. 7 7 The supported geometries are quite restricted, see help 8 read_polygon -- Reads either a polygon or line shapefile or a csv as a polygon 8 9 readShpPointsAndAttributes -- read a multi-point shapefile with its attributes into ANUGA 9 10 … … 45 46 import sys 46 47 import os 48 import os.path 47 49 import copy 48 50 import struct 49 51 import numpy 50 52 #from matplotlib import path 53 import anuga 51 54 from anuga.geometry.polygon import inside_polygon 52 55 … … 82 85 #dataSrc=ogr.Open(shapefile) 83 86 layer=dataSrc.GetLayer() 84 87 88 # Check it is a polygon 89 layerType=ogr.GeometryTypeToName(layer.GetGeomType()) 90 if not layerType=='Polygon': 91 msg= shapefile +' is not a polygon shapefile' 92 raise Exception, msg 93 85 94 # Need a single polygon 86 95 try: … … 118 127 #dataSrc=ogr.Open(shapefile) 119 128 layer=dataSrc.GetLayer() 120 129 130 # Check it is a line 131 layerType=ogr.GeometryTypeToName(layer.GetGeomType()) 132 if not layerType=='Line String': 133 msg= shapefile +' is not a line shapefile' 134 raise Exception, msg 135 121 136 # Need a single line 122 137 try: 123 assert (len(layer)==1)138 assert len(layer)==1 124 139 except: 125 140 print shapefile … … 134 149 135 150 #################### 136 151 def read_polygon(filename): 152 """ 153 154 Read a shapefile (polygon or line) or an anuga_polygon csv file as an anuga polygon 155 156 Try to automatically do the correct thing based on the filename 157 158 """ 159 # Check the file exists 160 msg= 'Could not read '+ filename 161 assert os.path.isfile(filename), msg 162 163 # Get the file extension type 164 fileNameNoExtension , fileExtension = os.path.splitext(filename) 165 166 if fileExtension == '.shp': 167 # Read as either a polygon or line shapefile 168 try: 169 outPol=readShp_1PolyGeo(filename) 170 assert len(outPol)>1 171 except: 172 try: 173 outPol= readShp_1LineGeo(filename) 174 assert len(outPol)>1 175 except: 176 msg= 'Could not read '+ filename +' as either polygon or line shapefile' 177 else: 178 try: 179 # Read as an anuga polygon file 180 outPol=anuga.read_polygon(filename) 181 except: 182 msg = 'Failed reading polygon '+ filename + ' with anuga.utilities.spatialInputUtils.read_polygon' 183 raise Exception, msg 184 185 return outPol 186 187 #################### 188 137 189 def readShpPtsAndAttributes(shapefile): 138 190 """ … … 161 213 162 214 return [pts, attribute, attributeNames] 215 216 ######################################## 217 def readShpPts(shapefile): 218 """ 219 Wrapper around readShpPtsAndAttributes 220 Only get the points 221 """ 222 223 out=readShpPtsAndAttributes(shapefile)[0] 224 return out 225 226 ######################################## 227 def read_points(filename): 228 """ 229 Reads x,y geometries from a point shapefile or csv file (anuga polygon type format), 230 and returns as a list of lists 231 """ 232 # Check the file exists 233 msg= 'Could not read '+ filename 234 assert os.path.isfile(filename), msg 235 236 # Get the file extension type 237 fileNameNoExtension , fileExtension = os.path.splitext(filename) 238 239 if fileExtension=='.shp': 240 try: 241 points = readShpPts(filename) 242 except: 243 msg = 'Could not read points from ' + filename 244 raise Exception, msg 245 else: 246 # Assume txt format 247 try: 248 #points=numpy.genfromtxt(filename,delimiter=',',skip_header=1) 249 #points=points[:,0:2].tolist() 250 points=anuga.read_polygon(filename) 251 except: 252 msg = 'Could not read points from ' + filename +\ 253 '. Make sure it has a single header row, with comma separator, and the first 2 columns are x,y' 254 raise Exception, msg 255 return points 163 256 164 257 ######################################## … … 729 822 breakLines=copy.copy(breakLinesIn) 730 823 riverWalls=copy.copy(riverWallsIn) 731 824 825 # Quick exit 826 if (breakLines == {}) and (riverWalls == {}): 827 return [bounding_polygon, breakLines, riverWalls] 828 732 829 # Clean intersections of breakLines with itself 733 830 if(verbose): … … 905 1002 906 1003 ######################################### 907 def readListOfBreakLines( shapefileList):908 """ 909 Take a list with the names of shapefiles 1004 def readListOfBreakLines(fileList): 1005 """ 1006 Take a list with the names of shapefiles or anuga_polygon csv files 910 1007 911 1008 They are assumed to be '2D breaklines', so we just read their … … 914 1011 Read them in 915 1012 916 INPUT: shapefileList -- a list of shapefilenames [e.g. from glob.glob('GIS/Breaklines/*.shp')]1013 INPUT: fileList -- a list of shapefile and/or anuga_polygon csv filenames [e.g. from glob.glob('GIS/Breaklines/*.shp')] 917 1014 918 1015 OUTPUT: dictionary with breaklines [filenames are keys] … … 920 1017 921 1018 allBreakLines={} 922 for shapefile in shapefileList:923 allBreakLines[shapefile]=read Shp_1LineGeo(shapefile)1019 for shapefile in fileList: 1020 allBreakLines[shapefile]=read_polygon(shapefile) #readShp_1LineGeo(shapefile) 924 1021 925 1022 return allBreakLines
Note: See TracChangeset
for help on using the changeset viewer.