Skip to content

Commit f89d583

Browse files
author
sreeder
committed
fix issue with spatialreferences
1 parent 9594e6d commit f89d583

File tree

7 files changed

+126
-1741
lines changed

7 files changed

+126
-1741
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
language: python
1+
git blanguage: python
22
sudo: required
33
# if the https://travis-ci.org/ODM2/ODM2PythonAPI/requests ever says: missing config
44
# validate at: http://lint.travis-ci.org/

Examples/Sample.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
# createconnection (dbtype, servername, dbname, username, password)
1919
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
2020
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
21+
2122
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")#win MSSQL
2223
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
2324
# session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/ODM2/usecases/WOF_to_ODM2/ODM2.sqlite', 2.0)
2425

2526

2627

28+
2729
#_session = session_factory.getSession()
2830
read = ReadODM2(session_factory)
2931
create =CreateODM2(session_factory)
@@ -60,7 +62,7 @@
6062
siteFeatures = read.getSamplingFeatures()
6163
# siteFeatures = read.getSamplingFeatures(type='Site')
6264
numSites = len(siteFeatures)
63-
65+
print ("Successful query")
6466
for x in siteFeatures:
6567
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureTypeCV )
6668
except Exception as e:
@@ -69,7 +71,7 @@
6971

7072
# Now get the SamplingFeature object for a SamplingFeature code
7173
try:
72-
sf = read.getSamplingFeatures(code=['USU-LBR-Mendon'])[0]
74+
sf = read.getSamplingFeatures(codes=['USU-LBR-Mendon'])[0]
7375
print(sf)
7476
print("\n-------- Information about an individual SamplingFeature ---------")
7577
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n")

odm2api/ODM2/models.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class SamplingFeatures(Base):
279279
index=True)
280280
Elevation_m = Column('elevation_m', Float(53))
281281
ElevationDatumCV = Column('elevationdatumcv', ForeignKey(CVElevationDatum.Name), index=True)
282-
FeatureGeometry = Column('featuregeometry', Geometry) # String(50))#
282+
FeatureGeometry = Column('featuregeometry', String(50))#Geometry) #
283283
FeatureGeometryWKT = Column('featuregeometrywkt', String(50))
284284
# FeatureGeometry = Column('featuregeometry', BLOB) # custom geometry queries
285285
__mapper_args__ = {
@@ -289,30 +289,30 @@ class SamplingFeatures(Base):
289289
(SamplingFeatureTypeCV == "Site", "Site"),
290290
], else_="samplingfeatures"),
291291
'polymorphic_identity':'samplingfeatures',
292-
# 'with_polymorphic':'*'
293-
}
294292

293+
}
295294

296295

297-
def shape(self):
298-
"""
299-
Method name based on shapely shapely.geometry.shape() function.
300-
Returns a shapely geometry object
301-
:return geomshape:
302-
"""
303-
_FeatureGeometry = self.FeatureGeometry
304-
geomshape = None
305-
if _FeatureGeometry is not None:
306-
print _FeatureGeometry
307-
print _FeatureGeometry.geom_wkb
308-
if is_hex(_FeatureGeometry.geom_wkb):
309-
# to parse wkb hex string directly
310-
geomshape = wkb.loads(_FeatureGeometry.geom_wkb, hex=True)
311-
# _FeatureGeometry = GeometryColumn('featuregeometry', Geometry)
312-
else:
313-
geomshape = wkt.loads(str(_FeatureGeometry.geom_wkb))
314296

315-
return geomshape
297+
# def shape(self):
298+
# """
299+
# Method name based on shapely shapely.geometry.shape() function.
300+
# Returns a shapely geometry object
301+
# :return geomshape:
302+
# """
303+
# _FeatureGeometry = self.FeatureGeometry
304+
# geomshape = None
305+
# if _FeatureGeometry is not None:
306+
# print _FeatureGeometry
307+
# print _FeatureGeometry.geom_wkb
308+
# if is_hex(_FeatureGeometry.geom_wkb):
309+
# # to parse wkb hex string directly
310+
# geomshape = wkb.loads(_FeatureGeometry.geom_wkb, hex=True)
311+
# # _FeatureGeometry = GeometryColumn('featuregeometry', Geometry)
312+
# else:
313+
# geomshape = wkt.loads(str(_FeatureGeometry.geom_wkb))
314+
#
315+
# return geomshape
316316

317317
def __repr__(self):
318318
# geom = self.shape()
@@ -327,7 +327,7 @@ def __repr__(self):
327327
self.Elevation_m, self.FeatureGeometryWKT)
328328

329329

330-
GeometryDDL(SamplingFeatures.__table__) # Geoalchemy1
330+
# GeometryDDL(SamplingFeatures.__table__) # Geoalchemy1
331331

332332

333333
class FeatureActions(Base):

odm2api/ODM2/services/createService.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,78 +24,117 @@ def create(self, values):
2424
self._session.add(values)
2525
self._session.commit()
2626

27+
2728
def createVariable(self, var):
2829
self._session.add(var)
2930
self._session.commit()
31+
self._session.flush()
32+
return var
3033

3134
def createMethod(self, method):
3235
self._session.add(method)
3336
self._session.commit()
37+
self._session.flush()
38+
return method
3439

3540
def createProcessingLevel(self, proclevel):
3641
self._session.add(proclevel)
3742
self._session.commit()
43+
self._session.flush()
44+
return proclevel
3845

3946
def createSamplingFeature(self, samplingfeature):
4047
self._session.add(samplingfeature)
4148
self._session.commit()
49+
self._session.flush()
50+
return samplingfeature
4251

4352
def createUnit(self, unit):
4453
self._session.add(unit)
4554
self._session.commit()
55+
self._session.flush()
56+
return unit
4657

4758
def createOrganization(self, org):
4859
self._session.add(org)
4960
self._session.commit()
61+
self._session.flush()
62+
return org
5063

5164
def createPerson(self, person):
5265
self._session.add(person)
5366
self._session.commit()
67+
self._session.flush()
68+
return person
5469

5570
def createAffiliation(self, affiliation):
5671
self._session.add(affiliation)
5772
self._session.commit()
73+
self._session.flush()
74+
return affiliation
5875

5976
def createDataset(self, dataset):
6077
self._session.add(dataset)
6178
self._session.commit()
79+
self._session.flush()
80+
return dataset
6281

6382
def createDatasetResults(self, datasetresult):
6483
self._session.add(datasetresult)
6584
self._session.commit()
85+
self._session.flush()
86+
return datasetresult
6687

6788
def createAction(self, action, actionby):
6889
self._session.add(action)
90+
self._session.commit()
91+
self._session.flush()
92+
actionby.ActionID = action.ActionID
6993
self._session.add(actionby)
7094
self._session.commit()
95+
return action
7196

7297
def createRelatedAction(self, relatedaction):
7398
self._session.add(relatedaction)
7499
self._session.commit()
100+
self._session.flush()
101+
return relatedaction
75102

76103
def createResult(self, result):
77104
self._session.add(result)
78105
self._session.commit()
106+
self._session.flush()
107+
return result
79108

80-
def createResultValues(self, values):
81-
self._session.add(values)
109+
def createResultValue(self, value):
110+
self._session.add(value)
82111
self._session.commit()
112+
self._session.flush()
113+
return value
83114

84115
def createSpatialReference(self, spatialref):
85116
self._session.add(spatialref)
86117
self._session.commit()
118+
self._session.flush()
119+
return spatialref
87120

88121
def createModel(self, model):
89122
self._session.add(model)
90123
self._session.commit()
124+
self._session.flush()
125+
return model
91126

92127
def createRelatedModel(self, relatedmodel):
93128
self._session.add(relatedmodel)
94129
self._session.commit()
130+
self._session.flush()
131+
return relatedmodel
95132

96133
def createSimulation(self, simulation):
97134
self._session.add(simulation)
98135
self._session.commit()
136+
self._session.flush()
137+
return simulation
99138

100139
def createTimeSeriesResultValues(self, datavalues):
101140
try:

0 commit comments

Comments
 (0)