GRASS 6 Tutorial/Vector data management: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(+figure explaining layers)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Vector data management==
==Vector data management==
===Overview===
The native GRASS vector format provides:
*Vector topology
*m:n mapping of geometry features to attributes
*Vector layers
*OGC Simple Features <-> Topological Vector Conversion
*Database Management system (DBMS)
*SQLite, PostgreSQL + PostGIS, MySQL, ODBC (, DBF)
The vector geometry types supported in GRASS includes:
*Point
*Centroid
*Line
*Boundary
*Area (Boundaries + Centroid)
*Face (3D Area)
*[Kernel (3D Centroid)]
*[Volumes (Faces + Kernel)]
All types are '''true 3D''': x,y,z
The examples that follow in this section on vector data management are based on the datasets available [http://data.neteler.org/geostat2012/north_carolina here]
===Importing Vector data===
===Importing Vector data===
The GRASS modules <code>v.in.*</code> and <code>v.out.*</code> handle the importing and exporting of Vector datasets.  
The GRASS modules ''<code>v.in.*</code>'' and '''<code>v.out.*</code>''' handle the importing and exporting of Vector datasets.  
<code>v.in.ogr</code> is widely used and has simplified the import of vector data; [http://www.gdal.org/ogr/ogr_formats.html OGR] itself support a wide range of formats.
<code>v.in.ogr</code> is widely used and has simplified the import of vector data; [http://www.gdal.org/ogr/ogr_formats.html OGR] itself support a wide range of formats.
<code>v.out.ogr</code> always exports the entire vector map
<code>v.out.ogr</code> always exports the entire vector map
Line 107: Line 84:
  v.category in=points out=points_final op=add
  v.category in=points out=points_final op=add
  v.category points_final op=report
  v.category points_final op=report
You can then add a new attribute table to the vector file using <code>v.db.addtable</code>
v.db.addtable map=points


You can replicate the above procedure for three dimensional data (XYZ), by modifying the <code>v.in.ascii</code> argument list
You can replicate the above procedure for three dimensional data (XYZ), by modifying the <code>v.in.ascii</code> argument list
Line 121: Line 101:
  cat coords.txt | v.in.ascii -z out=points
  cat coords.txt | v.in.ascii -z out=points


====Import an XY table from a DBMS or Spreadsheet====
If you have a list of coordinates (x,y) with associated attributes stored in a spreadsheet table (DBF, CSV, Excel, etc). It's fairly easy to generate a map from them using <code>v.in.db</code>. In the following example, we import the table, meteostations that has the columns 'east', 'north', 'quota' (z) and some attribute columns.
v.in.db driver=pg database="host=myserver.itc.it,dbname=mydb,user=name" table=meteostations x=east y=north z=quota  key=id output=meteostations
This command creates the new vector map (native format) with attributes table in a DBF file.
We can display these points in a display monitor and query them as follows:
d.mon start=x0
d.vect meteostations
d.what.vect


====Importing a DXF file====
====Importing a DXF file====
Line 151: Line 144:


This can also be done using the GUI interface
This can also be done using the GUI interface
[[File:import_dxf.png|400px]]
[[File:import_dxf.png|400px]]


And then visualised within the map display
And then visualised within the map display
[[File:dxf_display.png|400px]]
[[File:dxf_display.png|400px]]


Line 167: Line 162:


Introductory information on [http://grass.ibiblio.org/grass63/manuals/html63_user/vectorintro.html vector data processing] is available from the help manual.
Introductory information on [http://grass.ibiblio.org/grass63/manuals/html63_user/vectorintro.html vector data processing] is available from the help manual.
===[[Grass Six Tutorial Default Settings]]===
      -  Default settings for vector geometry;
          for vector attributes; for db.* modules
===[[Grass Six Tutorial Geometry Management]]===
http://grass.osgeo.org/grass57/tutorial/geom_storage.html
        -  General notes on Geometry
          management; Managing the default settings;
          GRASS vector architecture; Geometry stored in native format;
          Geometry stored in SHAPE file;
          Import/export of vector data Geometry;
          Generating vector geometry from various sources


===[[Grass Six Tutorial Attribute Management]]===
===[[Grass Six Tutorial Attribute Management]]===
Line 186: Line 168:
           management; Managing the default settings; Examples;
           management; Managing the default settings; Examples;
           Database Schema
           Database Schema
[[File:Catsnlayers.png|800px|thumb|alt=cats and layers in GRASS GIS|center|Figure 1 from [[Vector Database Management]]]]
[[Category: Tutorial]]

Latest revision as of 21:41, 24 March 2014

Vector data management

Importing Vector data

The GRASS modules v.in.* and v.out.* handle the importing and exporting of Vector datasets. v.in.ogr is widely used and has simplified the import of vector data; OGR itself support a wide range of formats. v.out.ogr always exports the entire vector map

Importing an ESRI Shapefile

The following code snippet is a simple usage of v.in.ogr, which imports an ESRI Shapefile into the native vector format:

v.in.ogr dsn=boundary_county.shp out=boundary_county 

However, v.in.ogr has many options to import subsets (defined spatially or by SQL) and vector types

The same can be achieved using the GRASS Graphical Interface. The Vector import interface can be accessed through the vector layer manager:

You can easily import a subset of your data by specifying the spatial extent or an SQL query defined within the where command line argument:

v.in.ogr --o dsn=./ output=subset layer=boundary_county where="NAME = 'DUPLIN' OR NAME = 'WAKE'"
 +----------------------------------------------------------------------------+
| Layer:           subset                                                    |
| Mapset:          PERMANENT                                                 |
| Location:        nc_spm_08_geostat                                         |
| Database:        /home/daniel/GRASSWiki/data                               |
| Title:                                                                     |
| Map scale:       1:1                                                       |
| Map format:      native                                                    |
| Name of creator: daniel                                                    |
| Organization:                                                              |
| Source date:     Wed Nov  7 16:10:01 2012                                  |
|----------------------------------------------------------------------------|
|   Type of Map:  vector (level: 2)                                          |
|                                                                            |
|   Number of points:       0               Number of areas:      2          |
|   Number of lines:        0               Number of islands:    2          |
|   Number of boundaries:   2               Number of faces:      0          |
|   Number of centroids:    2               Number of kernels:    0          |
|                                                                            |
|   Map is 3D:              No                                               |
|   Number of dblinks:      1                                                |
|                                                                            |
|         Projection: Lambert Conformal Conic                                |
|               N:   258121.97732598    S:   106860.16001618                 |
|               E:   732841.78315847    W:   610047.98051883                 |
|                                                                            |
|   Digitization threshold: 0                                                |
|   Comments:                                                                |
|                                                                            |
+----------------------------------------------------------------------------+

Virtual link an ESRI Shapefile

If you prefer not to import your vector datasets into the native GRASS vector format, you can create a virtual link to it using v.external

This can be done as follows:

v.external dsn=./ output=boundary_county layer=boundary_county
Building topology for vector map <boundary_county>...
Number of nodes: 1707
Number of primitives: 1981
Number of points: 0
Number of lines: 0
Number of boundaries: 1055
Number of centroids: 926
Number of areas: 1055 
Number of isles: 1055
Number of areas without centroid: 129

Import an XY/XYZ ASCII file

You can easily generate a GRASS point vector file from a text file containing X,Y coordinates.

642934|95324
675695|139878
623277|158224
716318|138568
742527|164776
735975|196227
755631|200158

Pipe the coordinates to the module v.in.ascii

cat coords.txt | v.in.ascii out=points

Add the categories to the vector points to facilitate attribute joins:

v.category in=points out=points_final op=add
v.category points_final op=report

You can then add a new attribute table to the vector file using v.db.addtable

v.db.addtable map=points

You can replicate the above procedure for three dimensional data (XYZ), by modifying the v.in.ascii argument list

You can easily generate a GRASS point vector file from a text file containing X,Y coordinates.

642934|95324|212
675695|139878|233
623277|158224|211
716318|138568|219
742527|164776|240
735975|196227|221
755631|200158|210
cat coords.txt | v.in.ascii -z out=points

Import an XY table from a DBMS or Spreadsheet

If you have a list of coordinates (x,y) with associated attributes stored in a spreadsheet table (DBF, CSV, Excel, etc). It's fairly easy to generate a map from them using v.in.db. In the following example, we import the table, meteostations that has the columns 'east', 'north', 'quota' (z) and some attribute columns.

v.in.db driver=pg database="host=myserver.itc.it,dbname=mydb,user=name" table=meteostations x=east y=north z=quota  key=id output=meteostations

This command creates the new vector map (native format) with attributes table in a DBF file.

We can display these points in a display monitor and query them as follows:

d.mon start=x0
d.vect meteostations
d.what.vect

Importing a DXF file

Both 2D and 3D DXF files can be imported into GRASS using the module v.in.dxf. This can be done very simply from the command-line as follows

v.in.dxf -1 Masterplanxy.dxf
 100%
Following DXF layers found:
Layer 1: line
Building topology for vector map <Masterplanxy>...
Registering primitives...
64302 primitives registered
405521 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 71142
Number of primitives: 64302
Number of points: 0
Number of lines: 64302
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0

This can also be done using the GUI interface

And then visualised within the map display

Exporting Vector data

Using the module v.out.ogr it is possible to export native GRASS Vector data to a range of formats:

  ESRI_Shapefile,MapInfo_File,TIGER,S57,DGN,Memory,BNA,CSV,GML,GPX,KML,GeoJSON,GMT,SQLite,ODBC,MSSQLSpatial,
  PostgreSQL,MySQL,PCIDSK,DXF,Geoconcept,GeoRSS,GPSTrackMaker,PGDump,GPSBabel,


Introductory information on vector data processing is available from the help manual.

Grass Six Tutorial Attribute Management

http://grass.osgeo.org/grass57/tutorial/attrib_storage.html

       - General notes on Attribute 
         management; Managing the default settings; Examples;
         Database Schema
cats and layers in GRASS GIS
Figure 1 from Vector Database Management