Vector Overlapping Areas: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(new)
 
m (remove hardcoded version specific urls, use latest version)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Introduction ==
Overlapping areas (e.g. as stored in a SHAPE file) can be represented as a topological model through M:N mapping: each area can belong to several categories, several areas can have the same category. If you want to get the coverage for a particular Landsat scene, just select the path and row with where="PATH = x and row = y". See also the manual of {{cmd|v.buffer}} for a similar example.
== FAQ ==
'''Q:''' How can I determine the number of overlapping features per location after import of SHAPE file?
'''Q:''' How can I determine the number of overlapping features per location after import of SHAPE file?


'''A:''' You can run this (example):
'''A:''' You can run this (example) - note that it won't work with the DBF driver but requires SQLite, PostgreSQL, MySQL, or... driver:


  # solution one
 
   v.in.ogr dsn=./shp/ layer=fireHistory output=fireHistory
   v.in.ogr dsn=./shp/ layer=fireHistory output=fireHistory
   v.category input=fireHistory output=tmpFire
 
   v.db.addtable map=tmpFire table=tmpFire_2 layer=2 columns='num,int'
   v.category input=fireHistory output=tmpFire type=centroid
  v.to.db map=tmpFire layer=2 qlayer=1 option=query col=num qcol='count(*)' type=centroid
   v.db.addtable map=tmpFire table=tmpFire_2 layer=2 columns='cat int'
      
      
   # Export it to a raster layer:
   # Export it to a raster layer:
   v.to.rast input=tmpFire layer=2 output=mf use=attr column=num
   v.to.rast input=tmpFire layer=2 output=mf use=attr column=num
  # another solution (tested under SQLite)
 
  v.in.ogr dsn=./shp/ layer=fireHistory output=fireHistory
 
  v.overlay ainput=fireHistory atype=area alayer=1 binput=fireHistory btype=area blayer=2 output=mf operator=or olayer=1,1,1 --overwrite
  v.db.renamecol map=mf layer=1 column=b_cat,countFires
  v.db.update map=mf layer=1 column=countFires value=1 where='countFires isnull'
 
  # Export it to a raster layer:
  v.to.rast input=fireHistory layer=1 output=mf use=attr column=countFires
== See also ==
* Intro to [[Vector Database Management|vector data model]] (with drawing)
* [[Vector topology cleaning]]
* [[Vector topology]]
* [http://grass.osgeo.org/programming7/vlibTopology.html#vlibTopoExamples Topology examples] (GRASS Programmer's Manual)
[[Category:FAQ]]
[[Category:Topology]]
[[Category:Vector]]

Latest revision as of 10:28, 4 December 2018

Introduction

Overlapping areas (e.g. as stored in a SHAPE file) can be represented as a topological model through M:N mapping: each area can belong to several categories, several areas can have the same category. If you want to get the coverage for a particular Landsat scene, just select the path and row with where="PATH = x and row = y". See also the manual of v.buffer for a similar example.

FAQ

Q: How can I determine the number of overlapping features per location after import of SHAPE file?

A: You can run this (example) - note that it won't work with the DBF driver but requires SQLite, PostgreSQL, MySQL, or... driver:

  # solution one
  
  v.in.ogr dsn=./shp/ layer=fireHistory output=fireHistory
  
  v.category input=fireHistory output=tmpFire type=centroid
  v.db.addtable map=tmpFire table=tmpFire_2 layer=2 columns='cat int'
   
  # Export it to a raster layer:
  v.to.rast input=tmpFire layer=2 output=mf use=attr column=num
  # another solution (tested under SQLite)
  
  v.in.ogr dsn=./shp/ layer=fireHistory output=fireHistory
  
  v.overlay ainput=fireHistory atype=area alayer=1 binput=fireHistory btype=area blayer=2 output=mf operator=or olayer=1,1,1 --overwrite
  v.db.renamecol map=mf layer=1 column=b_cat,countFires
  v.db.update map=mf layer=1 column=countFires value=1 where='countFires isnull'
  
  # Export it to a raster layer:
  v.to.rast input=fireHistory layer=1 output=mf use=attr column=countFires

See also