Skip to content

Instantly share code, notes, and snippets.

@oscar9
Last active October 30, 2019 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscar9/80ce430b8010f3b76a8bcccfd2e047ad to your computer and use it in GitHub Desktop.
Save oscar9/80ce430b8010f3b76a8bcccfd2e047ad to your computer and use it in GitHub Desktop.
# encoding: utf-8
import gvsig
from gvsig import geom
from org.gvsig.fmap.dal import DALLocator
from org.gvsig.fmap.dal import DataTypes
from org.gvsig.app import ApplicationLocator
from org.gvsig.fmap.geom import Geometry
def createOutputStore(pathShape,linesOutput):
manager = DALLocator.getDataManager()
serverParameters = manager.createServerExplorerParameters("H2Spatial")
serverParameters.setDynValue("database_file",pathShape)
serverExplorer = manager.openServerExplorer("H2Spatial",serverParameters)
#serverExplorer.getNewAddParameters()
p = serverExplorer.getAddParameters() #NewFeatureStoreParameters
p.setDynValue("Table","t1")
ft = p.getDefaultFeatureType() #manager.createFeatureType()
ft.add("PK",DataTypes.INT).setIsPrimaryKey(True)
ft.add("ID",DataTypes.STRING)
ft.add("GEOMETRY", DataTypes.GEOMETRY) #Geometry.TYPES.CURVE)
ft.get("GEOMETRY").setGeometryType(geom.LINE, geom.D2)
ft.get("GEOMETRY").setSRS(gvsig.currentView().getProjection())
#p.setDefaultFeatureType(ft)
serverExplorer.add("H2Spatial", p, True)
storeParameters = manager.createStoreParameters("H2Spatial")
storeParameters.setDynValue("database_file",pathShape)
storeParameters.setDynValue("Table","t1")
storeParameters.setDynValue("DefaultGeometryField","GEOMETRY")
#storeParameters.setDynValue("CRS",gvsig.currentView().getProjection())
store = manager.openStore("H2Spatial",storeParameters)
application = ApplicationLocator.getManager()
mapcontextmanager = application.getMapContextManager()
layer = mapcontextmanager.createLayer("Layer H2",store)
return layer
def main(*args):
pathShape = gvsig.getTempFile("resultMASTER_",".mv.db")
layer = createOutputStore(pathShape, True)
print layer
gvsig.currentView().addLayer(layer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment