Post

2 followers Follow
1
Avatar

EASI intrinsic functions in Python

Hi there,

I am currently working to translate some EASI scripts to Python, and was wondering if there is any simple way to use EASI intrinsic functions in Python? Or is there anywhere I can find the source code for these functions so that I can translate those to Python?

Thanks!
Logan

Logan R Drum

Please sign in to leave a comment.

4 comments

1
Avatar

Hi Logan,

It is not a very simple process to call EASI functions from python. You will basically have to run the EASI script using subprocess.call() function. However, if you need to pass variables to it, you may need to use python to directly edit the EASI script file. using the with open() as file: method.

for more information about the subprocess.call function, see http://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path

With all that being said, many of the EASI intrinsic functions can be replaced by using our new Python platform API and functions available in python or numpy.

Our python api is available at: http://www.pcigeomatics.com/python-api-doc/

Perhaps if you give me some more detail about some of the intrinsic functions you wish to convert to python, I can give more direction.

Good luck!

Shawn Melamed 1 vote
0
Avatar

Hi there Shawn,

Here are the functions that I am having issue with, couldn't find any of these in the new Python functions.

VECReadGeoInfo
VECNextShape
VECGetFieldCount
VECGetFieldType
VECGetFieldName
VECAddField
VECGetField
VECSetField
VECSetVertices
VECGetVertices
VECReadGeoInfo
VECWriteGeoInfo
VECCreateLayer

If there is an equivalent to any of these functions in Python, what may they be? Otherwise I will look into the couple of option you have suggested here.

Logan R Drum 0 votes
1
Avatar

Hi Again,

Right now our API has very limited support for vector layers. It is the next area we plan to release for our API, but we do not currently have a release date. Hopefully it will be available soon. For now it may be best to use open-source libraries. One of the benefits of moving to python is that there is no shortage of python libraries. I found fiona and shapely were good libraries.

Fiona is used as a data exchange library for importing and exporting vector layers from .shp files to the wkt (well known text) or wkb (well known binary). So you would have to convert the file to a shape file and then read it in to your script with fiona. With fiona, you can access vertices of individual shapes, attributes, modify them etc. It should cover most of your operations you're currently using: VECReadGeoInfo, VECNextShape, VECAddField, etc.

Shapely is a pretty awesome library as well and it compliments fiona. It is used for performing geometric operations, such as overlays, intersects, set theory, etc.

This workaround may not be ideal, but our transition to Python takes time, but it is in our plans to provide full vector support in the future.

Some useful resources:

fiona: http://toblerity.org/fiona/manual.html
Getting started with Fiona: http://gis.stackexchange.com/questions/120571/iterate-through-a-shapefile

Shapely: http://toblerity.org/shapely/manual.html

Shawn Melamed 1 vote
1
Avatar

Here is some basic code to help you get started:

import fiona
from shapely.geometry import shape

# to get the individual polygon vertices and basic information about shape
# do the following
c = fiona.open(r"C:\Users\melamed\Desktop\shapely\import_shape\georef.shp")
pol = c.next()
print pol


# to get just vertices, do the following:
geom = shape(pol['geometry'])
print geom


# to get attributes
for shape in fiona.open(r'C:\Users\melamed\Desktop\shapely\import_shape\georef.shp')
    for attr in shape['properties'].iteritems():
        print attr

# basic intersect analysis
intersect_analysis_layer = fiona.open(r'C:\Users\melamed\Desktop\shapely\import_shape\georef.shp')
geom_shape_a = shape(intersect_analysis_layer[0]['geometry'])
geom_shape_b = shape(intersect_analysis_layer[1]['geometry'])

geom_shape_a.intersects(geom_shape_b)

# result will be True or False
Shawn Melamed 1 vote