Commit ef4b6504183bff949fbecbb9982ca2ff6d8b0be8

Authored by Louis Baetens
1 parent e132fa66
Exists in master

RMV unused functions

Showing 1 changed file with 0 additions and 150 deletions   Show diff stats
ALCD/expand_point_region.py
... ... @@ -7,156 +7,6 @@ import os.path as op
7 7 import subprocess
8 8 import ogr
9 9 import numpy as np
10   -# -----------------------------------------------------------------
11   -# --------- For a polygon perspective -----------------------------
12   -# -----------------------------------------------------------------
13   -def create_buffer_zone(in_shp, out_shp, buffer_dist):
14   - ''' Create a buffer zone around all the valid points
15   - A zone is a polygon, which radius is defined by buffer_dist
16   -
17   - NOT USED ANYMORE
18   - '''
19   - # Get a Layer's Extent
20   - inDriver = ogr.GetDriverByName("ESRI Shapefile")
21   - inDataSource = inDriver.Open(in_shp, 0)
22   - inLayer = inDataSource.GetLayer()
23   -
24   - srs = inLayer.GetSpatialRef()
25   -
26   - # Save extent to a new Shapefile
27   - outDriver = ogr.GetDriverByName("ESRI Shapefile")
28   -
29   - # Remove output shapefile if it already exists
30   - if os.path.exists(out_shp):
31   - outDriver.DeleteDataSource(out_shp)
32   -
33   - # Create the output shapefile
34   - outDataSource = outDriver.CreateDataSource(out_shp)
35   - outLayer = outDataSource.CreateLayer("buff_layer", srs, geom_type=ogr.wkbPolygon)
36   -
37   - # Add a class field
38   - idField = ogr.FieldDefn("class", ogr.OFTInteger)
39   - outLayer.CreateField(idField)
40   -
41   - # Create the feature and set values
42   - for point in inLayer:
43   - ingeom = point.GetGeometryRef()
44   - geomBuffer = ingeom.Buffer(buffer_dist)
45   - current_class = point.GetField("class")
46   -
47   - # if class is None, there was an error at the begining,
48   - # so we discard the point
49   - if current_class != None:
50   - featureDefn = outLayer.GetLayerDefn()
51   - feature = ogr.Feature(featureDefn)
52   - feature.SetGeometry(geomBuffer)
53   - feature.SetField("class", current_class)
54   - outLayer.CreateFeature(feature)
55   -
56   - # Close DataSource
57   - inDataSource.Destroy()
58   - outDataSource.Destroy()
59   -
60   - return
61   -
62   -
63   -def simplify_geometry(in_shp, out_shp, tolerance = 100):
64   - ''' Simplification of a shapefile
65   - This allows to have lighter polygons, enhancing the rapidty
66   - '''
67   - print(" Geometry simplification")
68   - command = "ogr2ogr {} {} -simplify {}".format(out_shp, in_shp, str(tolerance))
69   - subprocess.call(command, shell=True)
70   - print("Done")
71   -
72   -# -----------------------------------------------------------------
73   -# --------- For a points perspective ------------------------------
74   -# -----------------------------------------------------------------
75   -
76   -def km_to_deg_convert(km, direction, latitude=0):
77   - ''' Convert roughly a distance in km to degrees
78   - The latitude parameter should be in degrees, and is needed for the
79   - computation in case of longitude
80   - '''
81   - if direction == 'lat':
82   - deg = km/110.574
83   - elif direction == 'lon':
84   - deg = km/(111.320*np.cos(np.radians(latitude)))
85   - else:
86   - deg = 0
87   - return deg
88   - #~ Latitude: 1 deg = 110.574 km
89   - #~ Longitude: 1 deg = 111.320*cos(latitude) km
90   -
91   -
92   -
93   -def create_neighbors(in_shp, out_shp, max_dist_X, max_dist_Y, nb_samples):
94   - ''' Create a neighbourhoud around all the points in a shapefile
95   - For each point, a grid around it is created, from -max_dist to +max_dist
96   - in each direction, with nb_samples in each direction
97   -
98   - NOT USED ANYMORE
99   - '''
100   - inDriver = ogr.GetDriverByName("ESRI Shapefile")
101   - inDataSource = inDriver.Open(in_shp, 0)
102   - inLayer = inDataSource.GetLayer()
103   -
104   - srs = inLayer.GetSpatialRef()
105   -
106   - # Save extent to a new Shapefile
107   - outDriver = ogr.GetDriverByName("ESRI Shapefile")
108   -
109   - # Watch out : sometimes the unit is meter, sometimes degree
110   - srs_unit = srs.GetAttrValue('unit')
111   -
112   - if srs_unit == 'Meter':
113   - print('Unit is meter, no change')
114   - elif srs_unit == 'Degree':
115   - print('Unit is degree, needs to be converted')
116   -
117   - # Remove output shapefile if it already exists
118   - if os.path.exists(out_shp):
119   - outDriver.DeleteDataSource(out_shp)
120   -
121   - # Create the output shapefile
122   - outDataSource = outDriver.CreateDataSource(out_shp)
123   - outLayer = outDataSource.CreateLayer("buff_layer", srs, geom_type=ogr.wkbPoint)
124   -
125   - # Add a class field
126   - classField = ogr.FieldDefn("class", ogr.OFTInteger)
127   - outLayer.CreateField(classField)
128   -
129   - print('{} neighbors will be created'.format(nb_samples*nb_samples*len(inLayer)) )
130   -
131   - # Create the feature and set values
132   - for point in inLayer:
133   - current_class = point.GetField("class")
134   - # if class is None, there was an error at the begining,
135   - # so we discard the point
136   - if current_class != None:
137   - ingeom = point.GetGeometryRef()
138   -
139   - # define the extent of the grid
140   - X_range = np.linspace(start=ingeom.GetX(0)-max_dist_X, stop=ingeom.GetX(0)+max_dist_X, num=nb_samples)
141   - Y_range = np.linspace(start=ingeom.GetY(0)-max_dist_Y, stop=ingeom.GetY(0)+max_dist_Y, num=nb_samples)
142   -
143   - # create the grid
144   - for i in range(len(X_range)):
145   - for j in range(len(X_range)):
146   - outpoint = ogr.Geometry(ogr.wkbPoint)
147   - outpoint.AddPoint(X_range[i], Y_range[j])
148   -
149   - featureDefn = outLayer.GetLayerDefn()
150   - feature = ogr.Feature(featureDefn)
151   - feature.SetGeometry(outpoint)
152   - feature.SetField("class", current_class)
153   - outLayer.CreateFeature(feature)
154   -
155   - # Close DataSource
156   - inDataSource.Destroy()
157   - outDataSource.Destroy()
158   -
159   - return
160 10  
161 11  
162 12 def create_squares(in_shp, out_shp, max_dist_X, max_dist_Y):
... ...