예제 #1
0
 def getCoords(self):
     # Create a new Map_info() object
     map = vect.pointer(vect.Map_info())
     # Load the vector map to Map_info() object. Level should be 2 (with topology)
     vect.Vect_open_old2(map, self.layer, "", "-1")
     # Get number of point features (1) in the layer
     n_lines = vect.Vect_get_num_primitives(map, 1)
     # Create new line and categories structures
     line = vect.Vect_new_line_struct()
     cats = vect.Vect_new_cats_struct()
     # Make an empty list to store all feature coordinates in
     coordsdict = {}
     # Iterate through all features and write their coordinates to the list
     for i in range(1, n_lines + 1):
         # Read next line from Map_info()
         vect.Vect_read_next_line(map, line, cats, 1)
         # Get line structure values
         x = line.contents.x[0]
         y = line.contents.y[0]
         # Create a new tuple of these coordinates and with their cat id (they do coincide with this iteration integer "i", so could also write cat = cats.contents.cat[0] and use "cat" instead "i") and append this to the general layer coordinate list.
         coordsdict[i] = (x,y)
     # Do some cleanup
     vect.Vect_destroy_line_struct(line)
     vect.Vect_destroy_cats_struct(cats)
     vect.Vect_close(map)
     # Return coordinate dictionary
     return coordsdict
예제 #2
0
파일: r.lcp.py 프로젝트: eomwandho/GRASS
 def getcoords(self):
     """ Method creating a dict() of point coordinates: {a:(xa,ya), b:(xb,yb)...} """
     # Create a new Map_info() object
     map = vect.pointer(vect.Map_info())
     # Load the vector map to Map_info() object. Level should be 2 (with topology)
     vect.Vect_open_old2(map, self.layer, "", "-1")
     # Get number of point features (1) in the layer
     n_lines = vect.Vect_get_num_primitives(map, 1)
     # Create new line and categories structures
     line = vect.Vect_new_line_struct()
     cats = vect.Vect_new_cats_struct()
     # Make an empty list to store all feature cats and their coordinates in
     coordsdict = {}
     # Iterate through all features and write their coordinates to the list
     for i in xrange(0, n_lines):
         # Read next line from Map_info()
         vect.Vect_read_next_line(map, line, cats, 1)
         # Get line structure values, i.e. coordinates
         x = line.contents.x[0]
         y = line.contents.y[0]
         # Get the point category number
         cat = cats.contents.cat[0]
         coordsdict[cat] = (x,y)
     # Do some cleanup
     vect.Vect_destroy_line_struct(line)
     vect.Vect_destroy_cats_struct(cats)
     vect.Vect_close(map)
     # Return coordinate dictionary. Example: {1: (635185.6745587245, 6434401.869609355), 3: (634763.0860512792, 6437526.1793751), 4: (636855.7953351085, 6435785.045250954), 5: (636705.1202666728, 6432286.035328391), 6: (633607.9105266054, 6432286.035328391), 7: (632762.4559759387, 6435655.297275356)}
     return coordsdict
예제 #3
0
파일: r.lcp.py 프로젝트: yangmaoer/GRASS
 def getcoords(self):
     """ Method creating a dict() of point coordinates: {a:(xa,ya), b:(xb,yb)...} """
     # Create a new Map_info() object
     map = vect.pointer(vect.Map_info())
     # Load the vector map to Map_info() object. Level should be 2 (with topology)
     vect.Vect_open_old2(map, self.layer, "", "-1")
     # Get number of point features (1) in the layer
     n_lines = vect.Vect_get_num_primitives(map, 1)
     # Create new line and categories structures
     line = vect.Vect_new_line_struct()
     cats = vect.Vect_new_cats_struct()
     # Make an empty list to store all feature cats and their coordinates in
     coordsdict = {}
     # Iterate through all features and write their coordinates to the list
     for i in xrange(0, n_lines):
         # Read next line from Map_info()
         vect.Vect_read_next_line(map, line, cats, 1)
         # Get line structure values, i.e. coordinates
         x = line.contents.x[0]
         y = line.contents.y[0]
         # Get the point category number
         cat = cats.contents.cat[0]
         coordsdict[cat] = (x, y)
     # Do some cleanup
     vect.Vect_destroy_line_struct(line)
     vect.Vect_destroy_cats_struct(cats)
     vect.Vect_close(map)
     # Return coordinate dictionary. Example: {1: (635185.6745587245, 6434401.869609355), 3: (634763.0860512792, 6437526.1793751), 4: (636855.7953351085, 6435785.045250954), 5: (636705.1202666728, 6432286.035328391), 6: (633607.9105266054, 6432286.035328391), 7: (632762.4559759387, 6435655.297275356)}
     return coordsdict
예제 #4
0
 def featCount(self):
     """ Method returning the number of features in the layer """
     # Create a new Map_info() object
     map = vect.pointer(vect.Map_info())
     # Load the vector map to Map_info() object. Level should be 2 (with topology)
     vect.Vect_open_old2(map, self.layer, "", "-1")
     # Get number of point features (1) in the layer
     n_lines = vect.Vect_get_num_primitives(map, 1)
     # Do some cleanup
     vect.Vect_close(map)
     # Return number of features in the layer as a tuple
     return n_lines
예제 #5
0
파일: r.lcp.py 프로젝트: yangmaoer/GRASS
 def featcount(self):
     """ Method returning the number of features in the layer """
     # Create a new Map_info() object
     map = vect.pointer(vect.Map_info())
     # Load the vector map to Map_info() object. Level should be 2 (with topology)
     vect.Vect_open_old2(map, self.layer, "", "-1")
     # Get number of point features (1) in the layer
     n_feats = vect.Vect_get_num_primitives(map, 1)
     # Close the Map_info() object
     vect.Vect_close(map)
     # Return number of features in the layer (integer)
     return n_feats
예제 #6
0
def main():
    # Input data
    points = options['points']                  # Point layer
    dem = options['dem']                        # Elevation model
    curvature = "c" if flags['c'] else ""       # Earth's curvature flag
    obs_height = options['obs_height']          # Observer's height
    target_height = options['target_height']    # Target height offset
    maxradius = options['maxradius']            # Max radius
    output_prefix = options['prefix']           # Output layer prefix
    
    # Get individual point coordinates and write them to dictionary
    # Create a new Map_info() object
    map = vect.pointer(vect.Map_info())
    # Load the vector map to Map_info() object. Level should be 2 (with topology)
    vect.Vect_open_old2(map, points, "", "-1")
    # Get number of point features (1) in the layer
    n_lines = vect.Vect_get_num_primitives(map, 1)
    # Create new line and categories structures
    line = vect.Vect_new_line_struct()
    cats = vect.Vect_new_cats_struct()
    # Make an empty dictionary to store all feature cats and their coordinates in
    coordsdict = {}
    # Iterate through all features and write their coordinates to the dictionary
    for i in xrange(0, n_lines):
        # Read next line from Map_info()
        vect.Vect_read_next_line(map, line, cats, 1)
        # Get line structure values, i.e. coordinates
        x = line.contents.x[0]
        y = line.contents.y[0]
        # Get the point category number
        cat = cats.contents.cat[0]
        coordsdict[cat] = (x,y)
    # Do some cleanup
    vect.Vect_destroy_line_struct(line)
    vect.Vect_destroy_cats_struct(cats)
    vect.Vect_close(map)
    
    # Do the loop
    for pointnumber in range(1,n_lines + 1):
        # Get x and y coordinates from dictionary created earlier and merge them into one string
        xcoord, ycoord = coordsdict[pointnumber]
        point_coords = str(str(xcoord) + "," + str(ycoord))
        # Generate output raster name
        outraster = str(str(output_prefix) + str(pointnumber))
        # Run r.viewshed
        grass.run_command('r.viewshed', flags = curvature, overwrite = True, input = dem, output = outraster, coordinates = point_coords, obs_elev = obs_height, tgt_elev = target_height, max_dist = maxradius)