GRASS SoC Ideas 2012/High level map interaction/Vector

From GRASS-Wiki
Revision as of 15:14, 17 July 2012 by ⚠️Landa (talk | contribs) (categories)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

See major page GRASS SoC Ideas 2012/High level map interaction

Vector Maps

Vector Geometries

I would like to implement different Geometry classes:

  • point
  • (segment)
  • line
  • boundary
  • centroid
  • area
>>> pnt0 = Point(x0, y0)
>>> pnt1 = Point(x1, y1)
>>> pnt2 = Point(x2, y2)
>>> line0 = Line([pnt0, pnt1, pnt2])
>>> bound0 = Boundary([pnt0, pnt1, pnt2])
>>> area = Area(bount0, Centroid(x3, y3))

Line attributes and methods

Line should have attributes, like:

>>> line0.length # return the length
960.5
>>> line0.bbox # return the bbox>>> for segment in line.nseg
2
(pnt0, pnt1)
>>> line0.number # return the number line
>>> for segment in line.nseg # return the number of segments
2

Line is iterable and return a point object.

>>> for point in line0:
...     # do somenthing

Line should have a method to return a Segments.

>>> for segment in line.segs(): 
...     # return a list of tuple [(pnt0, pnt1), (pnt1, pnt2),]
...     # do somethig

>>> pnt0 in line0 # check if line contain point
True
>>> lineX in line0


Boundary

>>> bound0.perimeter()
1023.8
>>> bound.nseg # return the number of segments

>>> for point in bound0:
...     # do something

>>> for seg in bound0.segs():
...     # do something

Area

>>> area0.boundary # return a boundary object
>>> area0.centroid #return a point object
>>> area0.area() 
2034

All the geometries object should have methods like the python sets (may be not all):


Operation Equivalent Result len(s) return the number of points x in s test x for membership in s x not in s test x for non-membership in s s.issubset(t) s <= t test whether every element in s is in t s.issuperset(t) s >= t test whether every element in t is in s s.union(t) s | t new set with elements from both s and t s.intersection(t) s & t new set with elements common to s and t s.difference(t) s - t new set with elements in s but not in t s.symmetric_difference(t) s ^ t new set with elements in either s or t but not both s.copy() new set with a shallow copy of s

more details on python sets here:

http://docs.python.org/library/sets.html#set-objects

and/or use some methods like shapely:

http://toblerity.github.com/shapely/manual.html#binary-predicates

and

http://toblerity.github.com/shapely/manual.html#spatial-analysis-methods

another possibility could be to include shapely to add a native support to grass and topology.

And point, line, boundary and Area should have a:

  • buffer method, that return an Area object.
  • distance method, that return the minimal distance between objcts
  • wkt, return a well know text
  • wkb, return well know binary


Vector obj

Vect obj should have attributes like:

>>> roads = Vect('roads')
>>> roads.name
'roads'

As for raster object should have an history object:

>>> road.hist.creator
'pietro'


>>> roads.exist()
True
>>> roads.isopen()
False
>>> for row in roads:
...     # do something
...

>>> roads.open(topology = True)

Layer

Topology

Categories

Attributes table

The attributes table should be inherit from Structured Array class

http://docs.scipy.org/doc/numpy/user/basics.rec.html#structured-arrays

Vector should have a connection attribute:

>>> roads.connect
Connection (db='postgresql', user='pietro', etc.)
>>> roads.exist()
False
>>> roads.attributes # return a OrderedDict
OrderedDict([('cat', int),('name', str),('geo', geometry)])

we can add a new column with

>>> roads.attributes['length'] = float
>>> for road in roads:
...     road['length'] = road.length

#as for numpy array:
>>> (roads['length'] <= 1000).nonzero() # return the index of all the roads that respect this conditions

allow SQL query:

>>> roads.sql("SELECT * FROM roads WHERE length <= 1000 ORDER BY length LIMIT 100")