예제 #1
0
    def num_primitive_of(self, primitive):
        """Return the number of primitive

        :param primitive: the name of primitive to query; the supported values are:

                            * *boundary*,
                            * *centroid*,
                            * *face*,
                            * *kernel*,
                            * *line*,
                            * *point*
                            * *area*
                            * *volume*

        :type primitive: str

        ::

            >>> test_vect = VectorTopo(test_vector_name)
            >>> test_vect.open(mode='r')
            >>> test_vect.num_primitive_of('point')
            3
            >>> test_vect.num_primitive_of('line')
            3
            >>> test_vect.num_primitive_of('centroid')
            4
            >>> test_vect.num_primitive_of('boundary')
            11
            >>> test_vect.close()

        ..
        """
        return libvect.Vect_get_num_primitives(self.c_mapinfo,
                                               VTYPE[primitive])
예제 #2
0
    def num_primitive_of(self, primitive):
        """Primitive are:

            * "boundary",
            * "centroid",
            * "face",
            * "kernel",
            * "line",
            * "point"

        ::

            >>> rail = VectTopo('rail')
            >>> rail.open()
            >>> rail.num_primitive_of('line')
            10837
            >>> municip = VectTopo('boundary_municp_sqlite')
            >>> municip.open()
            >>> municip.num_primitive_of('line')
            0
            >>> municip.num_primitive_of('centroid')
            3579
            >>> municip.num_primitive_of('boundary')
            5128
            >>> rail.close()
            >>> municip.close()

        ..
        """
        return libvect.Vect_get_num_primitives(self.c_mapinfo,
                                               VTYPE[primitive])
예제 #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
파일: 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
예제 #5
0
def _read_vector_info(name, mapset):
    """Read the vector map info from the file system and store the content
       into a dictionary

       This method uses the ctypes interface to the vector libraries
       to read the map metadata information

       :param name: The name of the map
       :param mapset: The mapset of the map
       :returns: The key value pairs of the map specific metadata, or None in
                 case of an error
    """

    kvp = {}

    if not libgis.G_find_vector(name, mapset):
        return None

    # The vector map structure
    Map = libvector.Map_info()

    # We open the maps always in topology mode first
    libvector.Vect_set_open_level(2)
    with_topo = True

    # Code lend from v.info main.c
    if libvector.Vect_open_old_head2(byref(Map), name, mapset, "1") < 2:
        # force level 1, open fully
        # NOTE: number of points, lines, boundaries, centroids,
        # faces, kernels is still available
        libvector.Vect_set_open_level(1)  # no topology
        with_topo = False
        if libvector.Vect_open_old2(byref(Map), name, mapset, "1") < 1:
            logging.error(
                _("Unable to open vector map <%s>" %
                  (libvector.Vect_get_full_name(byref(Map)))))
            return None

    # Release the vector spatial index memory when closed
    libvector.Vect_set_release_support(byref(Map))

    # Read the extent information
    bbox = libvector.bound_box()
    libvector.Vect_get_map_box(byref(Map), byref(bbox))

    kvp["north"] = bbox.N
    kvp["south"] = bbox.S
    kvp["east"] = bbox.E
    kvp["west"] = bbox.W
    kvp["top"] = bbox.T
    kvp["bottom"] = bbox.B

    kvp["map3d"] = bool(libvector.Vect_is_3d(byref(Map)))

    # Read number of features
    if with_topo:
        kvp["points"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_POINT)
        kvp["lines"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_LINE)
        kvp["boundaries"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_BOUNDARY)
        kvp["centroids"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_CENTROID)
        kvp["faces"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_FACE)
        kvp["kernels"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_KERNEL)

        # Summarize the primitives
        kvp["primitives"] = kvp["points"] + kvp["lines"] + \
            kvp["boundaries"] + kvp["centroids"]
        if kvp["map3d"]:
            kvp["primitives"] += kvp["faces"] + kvp["kernels"]

        # Read topology information
        kvp["nodes"] = libvector.Vect_get_num_nodes(byref(Map))
        kvp["areas"] = libvector.Vect_get_num_areas(byref(Map))
        kvp["islands"] = libvector.Vect_get_num_islands(byref(Map))
        kvp["holes"] = libvector.Vect_get_num_holes(byref(Map))
        kvp["volumes"] = libvector.Vect_get_num_primitives(
            byref(Map), libvector.GV_VOLUME)
    else:
        kvp["points"] = None
        kvp["lines"] = None
        kvp["boundaries"] = None
        kvp["centroids"] = None
        kvp["faces"] = None
        kvp["kernels"] = None
        kvp["primitives"] = None
        kvp["nodes"] = None
        kvp["areas"] = None
        kvp["islands"] = None
        kvp["holes"] = None
        kvp["volumes"] = None

    libvector.Vect_close(byref(Map))

    return kvp