Revision 756
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/examples/vectorial_data/05_crearPuntosAleatorios.py | ||
---|---|---|
1 |
# encoding: utf-8 |
|
2 |
|
|
3 |
import gvsig |
|
4 |
from gvsig import currentView |
|
5 |
from gvsig import createFeatureType |
|
6 |
from gvsig.geom import POINT, D2, createPoint |
|
7 |
from gvsig import createShape |
|
8 |
|
|
9 |
import random |
|
10 |
|
|
11 |
def createPointLayer(): |
|
12 |
# |
|
13 |
# Vamos a crear los puntos sobre el area representada en la vista. |
|
14 |
# usaremos la funcion random.randint de python, que solo usa enteros |
|
15 |
# y devuelbe enteros, asi que usaremos valores decimales con tres |
|
16 |
# decimanes representandolos como de coma fija en un entero. |
|
17 |
# |
|
18 |
# 1.123 ===> 1123 |
|
19 |
# |
|
20 |
# Y cuando vayamos a crear los puntos con esos valores los volveremos |
|
21 |
# a transformar en decimales dividienlos por 1000.0 |
|
22 |
# |
|
23 |
|
|
24 |
# |
|
25 |
# Para eso, lo primero obtendremos el Envelope de la vista |
|
26 |
envelope = currentView().getMapContext().getViewPort().getEnvelope() |
|
27 |
|
|
28 |
# |
|
29 |
# Calculamos los valores maximos y minimos de las coordenadas de |
|
30 |
# ese envelope como valores con tres decimales en coma fija representados |
|
31 |
# en un entero. |
|
32 |
# |
|
33 |
minx = int(envelope.getMinimum(0) * 1000) |
|
34 |
maxx = int(envelope.getMaximum(0) * 1000) |
|
35 |
miny = int(envelope.getMinimum(1) * 1000) |
|
36 |
maxy = int(envelope.getMaximum(1) * 1000) |
|
37 |
|
|
38 |
print minx, maxx |
|
39 |
print miny, maxy |
|
40 |
|
|
41 |
# |
|
42 |
# Creamos un shape con solo un campo geometria de tipo |
|
43 |
# punto 2D |
|
44 |
schema = createFeatureType() # DefaultFeatureType |
|
45 |
schema.append("GEOMETRY", "GEOMETRY") |
|
46 |
schema.get("GEOMETRY").setGeometryType(POINT, D2) |
|
47 |
puntos = createShape(schema, prefixname="puntos") |
|
48 |
|
|
49 |
# |
|
50 |
# Ponemos en edicion el nuevo shape vacio |
|
51 |
puntos.edit() |
|
52 |
|
|
53 |
# Vamos a crear 20 puntos |
|
54 |
for x in range(20): |
|
55 |
# |
|
56 |
# Calculamos la x e y y la dividimos por 1000.0 |
|
57 |
# para pasarla a double. |
|
58 |
x = random.randint(minx, maxx)/1000.0 |
|
59 |
y = random.randint(miny, maxy)/1000.0 |
|
60 |
# Creamos el punto |
|
61 |
point = createPoint(D2,x,y) |
|
62 |
# Lo añadimos a la capa de puntos |
|
63 |
puntos.append( { "GEOMETRY": point } ) |
|
64 |
|
|
65 |
# |
|
66 |
# Cuando hemos añadido todos los puntos terminamos la edicion |
|
67 |
puntos.finishEditing() |
|
68 |
|
|
69 |
# Por ultimo añadiremos la capa a la vista |
|
70 |
currentView().addLayer(puntos) |
|
71 |
|
|
72 |
# Y mostraremos por consola la ruta en la que se ha creado la capa |
|
73 |
print puntos.getDataStore().getFullName() |
|
74 |
|
|
75 |
return puntos |
|
76 |
|
|
77 |
def main(*args): |
|
78 |
createPointLayer() |
|
79 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/examples/vectorial_data/05_crearPuntosAleatorios.inf | ||
---|---|---|
1 |
[script] |
|
2 |
enable = true |
|
3 |
isolation = 0 |
|
4 |
|
|
5 |
[Unit] |
|
6 |
type = Script |
|
7 |
name = 05_crearPuntosAleatorios |
|
8 |
description = |
|
9 |
createdBy = |
|
10 |
version = |
|
11 |
|
|
12 |
[Script] |
|
13 |
main = main |
|
14 |
Lang = python |
|
15 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/data/MANZANAS_POB.prj | ||
---|---|---|
1 |
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/data/manzanas_puntos.prj | ||
---|---|---|
1 |
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]] |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/data/manzanas_parcelas.prj | ||
---|---|---|
1 |
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]] |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/data/manzanas_pob.prj | ||
---|---|---|
1 |
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]] |
Also available in: Unified diff