gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources / scripting / lib / geom.py @ 365
History | View | Annotate | Download (3.61 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
#
|
3 |
# File: gvsig.py
|
4 |
#
|
5 |
# Copyright (c) 2011 by Model Driven Development sl and Antonio Carrasco Valero
|
6 |
#
|
7 |
# GNU General Public License (GPL)
|
8 |
#
|
9 |
# This program is free software; you can redistribute it and/or
|
10 |
# modify it under the terms of the GNU General Public License
|
11 |
# as published by the Free Software Foundation; either version 2
|
12 |
# of the License, or (at your option) any later version.
|
13 |
#
|
14 |
# This program is distributed in the hope that it will be useful,
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
# GNU General Public License for more details.
|
18 |
#
|
19 |
# You should have received a copy of the GNU General Public License
|
20 |
# along with this program; if not, write to the Free Software
|
21 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
22 |
# 02110-1301, USA.
|
23 |
#
|
24 |
#
|
25 |
|
26 |
__author__ = """Antonio Carrasco Valero
|
27 |
Model Driven Development sl and Antonio Carrasco Valero
|
28 |
<carrasco@modeldd.org>
|
29 |
Victor Acevedo Royer <vacevedor@gmail.com>
|
30 |
"""
|
31 |
|
32 |
__docformat__ = 'plaintext'
|
33 |
|
34 |
|
35 |
from org.gvsig.fmap.mapcontext import MapContextLocator |
36 |
|
37 |
from java.lang import RuntimeException |
38 |
from java.lang import Throwable |
39 |
|
40 |
from org.gvsig.app import ApplicationLocator |
41 |
|
42 |
from org.gvsig.fmap.dal import DALLocator, DataTypes |
43 |
|
44 |
from org.gvsig.fmap.geom import Geometry, GeometryLocator#, Geometry.TYPES, Geometry.SUBTYPES |
45 |
|
46 |
|
47 |
from org.gvsig.tools import ToolsLocator |
48 |
|
49 |
import thread |
50 |
|
51 |
|
52 |
|
53 |
#GeometryTypes
|
54 |
AGGREGATE = Geometry.TYPES.AGGREGATE |
55 |
ARC = Geometry.TYPES.ARC |
56 |
CIRCLE = Geometry.TYPES.CIRCLE |
57 |
CURVE = Geometry.TYPES.CURVE |
58 |
ELLIPSE = Geometry.TYPES.ELLIPSE |
59 |
ELLIPTICARC = Geometry.TYPES.ELLIPTICARC |
60 |
GEOMETRY = Geometry.TYPES.GEOMETRY |
61 |
MULTICURVE = Geometry.TYPES.MULTICURVE |
62 |
MULTIPOINT = Geometry.TYPES.MULTIPOINT |
63 |
MULTISOLID = Geometry.TYPES.MULTISOLID |
64 |
MULTISURFACE = Geometry.TYPES.MULTISURFACE |
65 |
NULL = Geometry.TYPES.NULL |
66 |
POINT = Geometry.TYPES.POINT |
67 |
SOLID = Geometry.TYPES.SOLID |
68 |
SPLINE = Geometry.TYPES.SPLINE |
69 |
SURFACE = Geometry.TYPES.SURFACE |
70 |
|
71 |
# geometrySubTypes
|
72 |
D2= Geometry.SUBTYPES.GEOM2D |
73 |
DM2= Geometry.SUBTYPES.GEOM2DM |
74 |
D3= Geometry.SUBTYPES.GEOM3D |
75 |
DM3= Geometry.SUBTYPES.GEOM3DM |
76 |
UNKNOWN= Geometry.SUBTYPES.UNKNOWN |
77 |
|
78 |
def createGeometry(type, subtype=D2): |
79 |
"""
|
80 |
Create a new geometry with a concrete type and subtype
|
81 |
|
82 |
:param type: geometry type
|
83 |
:type type: string
|
84 |
:param subtype: geometry subtype
|
85 |
:type type: string
|
86 |
:return: geometry
|
87 |
:rtype: geometry
|
88 |
"""
|
89 |
|
90 |
#type = getGeometryType(type)
|
91 |
#subtype = getGeometrySubType(subtype)
|
92 |
|
93 |
geometryManager = GeometryLocator.getGeometryManager() |
94 |
geometry = geometryManager.create(type, subtype)
|
95 |
|
96 |
return geometry
|
97 |
|
98 |
def createPoint(x, y, subtype=D2): |
99 |
"""
|
100 |
Create a new point with a subtype and sets the value for the X and the Y
|
101 |
|
102 |
:param x: X coordinate value
|
103 |
:param y: Y coordinate value
|
104 |
:type x: double
|
105 |
:type y: double
|
106 |
:return: Point
|
107 |
:rtype: Point
|
108 |
"""
|
109 |
|
110 |
geometryManager = GeometryLocator.getGeometryManager() |
111 |
#subtype = getGeometrySubType(subtype)
|
112 |
point = geometryManager.createPoint(x, y, subtype) |
113 |
return point
|
114 |
|
115 |
def createMultiPoint(points, subtype=D2): |
116 |
"""
|
117 |
Create a new multipoint with a subtype from a list values of X and Y like
|
118 |
([x1, y1], [x2, y2], ...., [xn, yn])
|
119 |
|
120 |
:param points: list of tuples with X and Y values
|
121 |
:type points: list
|
122 |
:return: multipoint
|
123 |
:rtype: multipoint
|
124 |
"""
|
125 |
#subtype = getGeometrySubType(subtype)
|
126 |
multipoint = createGeometry(MULTIPOINT, subtype) |
127 |
|
128 |
for point in points: |
129 |
p = createPoint(point[0], point[1], subtype) |
130 |
multipoint.add(p) |
131 |
|
132 |
return multipoint
|
133 |
|
134 |
def createEnvelope(): |
135 |
#FIXME
|
136 |
pass
|
137 |
|
138 |
def main(): |
139 |
point = createPoint(1,1) |