[Gvsig_english] How to access schema from an input shapefile in scripting
Óscar Martínez
omartinez at gvsig.com
Thu Oct 13 18:00:21 CEST 2016
Hi!
If i understood correctly, you don't need to use the getSchema function.
I'm going to give you my solution with two test layers, give it a try
and tell us if that works for you or what exactly more do you need. If
you don't understand some part of the script i can explain it better.
Some help is inside the script, step by step.
I recommend to you to start learning scripting using the functions
currentLayer() (current layer selection in the table of contents) or
currentView().getLayer("layername") instead of using loadShapeFile
everytime. It's easier if you just have a loaded layer in your view and
access to each one each layer with currentLayer o getLayer.
If someone on the list want to know more about this part of scripting,
here are some links from the spanish docs (hope soon in english) related
to this post:
Access to features:
http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/acceso_a_objetos.html#entidad
Spatial operations:
http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/modulo_geom.html#operaciones-espaciales
Current functions:
http://downloads.gvsig.org/download/web/html/es/scripting_devel_guide/2.3/acceso_a_objetos.html
Any trouble here we are!
Best regards,
Óscar
Script (layers of this test are in EPSG:25830) (feature AREA1 is a
multipolygon):
# encoding: utf-8
import gvsig
def main(*args):
# You need to have one view with to layers opened on it
# The name of the layers will be the name that appear
# in the table of contents of the view
# To access to the layers that are already loaded in gvSIG
# gvsig.currentView() give us access to the opened view
# gvsig.currentView().getLayer(name) give us access a specified layer
points = gvsig.currentView().getLayer("points")
area = gvsig.currentView().getLayer("area")
# Access to the features
features_points = points.features()
features_area = area.features()
# if you want access to a selection of features, not all
# you will have to change `features()` with `getSelection()`
#features_points = points.getSelection()
#features_area = area.getSelection()
for farea in features_area:
print "\nChecking : ", farea.get("localId")
geom_farea = farea.geometry()
#for each area, check all points without intersection
for fpoint in features_points:
geom_fpoint = fpoint.geometry()
if not geom_farea.intersects(geom_fpoint):
print "\tArea: ", farea.get("localId"), " intersects
with :", fpoint.get("ID")
# work with the feature
Console output:
Running script testing_silvia_intersec.
Checking : AREA1
Area: AREA1 intersects with : 101
Area: AREA1 intersects with : 102
Area: AREA1 intersects with : 103
Area: AREA1 intersects with : 107
Checking : AREA2
Area: AREA2 intersects with : 103
Area: AREA2 intersects with : 104
Area: AREA2 intersects with : 105
Area: AREA2 intersects with : 106
Area: AREA2 intersects with : 107
Area: AREA2 intersects with : 108
Script testing_silvia_intersec terminated.
El 13/10/16 a las 15:05, Silvia Franceschi escribió:
> Hi all,
> I am trying to write my first script in gvSIG and Python, I need to
> read a point shapefile and filter some elements that are outside a
> defined area.
> To do this I have to read two input layers, one with the points and
> one with the area and then work on each single features of the point
> layer.
> I started with the selection of the input layers using a filechooser
> dialog (commonsdialog.filechooser) and then I need to obtain the
> schema of these layers, but it seems that the object filechooser do
> not have the .getSchema() function.
> Do you have any idea on how to obtain the schema from a vector layer
> selected using the filechooser?
>
> Thanks in advance for any help!
>
> Silvia
>
>
> --
> ing. Silvia Franceschi
> Via Latemar, 22
> 38030 Castello di Fiemme (TN)
>
> tel: 0039 -3384501332
>
>
> _______________________________________________
> Gvsig_internacional mailing list
> Gvsig_internacional at listserv.gva.es
>
> To see the archives, edit your preferences or unsubscribe from this mailing list, please access this url:
>
> https://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20161013/27f7a616/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shape_intersection_points.zip
Type: application/zip
Size: 3669 bytes
Desc: not available
URL: <http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20161013/27f7a616/attachment.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 152697 bytes
Desc: not available
URL: <http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20161013/27f7a616/attachment.png>
More information about the Gvsig_internacional
mailing list