Skip to content

Commit 9223295

Browse files
Merge pull request #16 from Loop3D/epsg_in_extents
fix: Add EPSG field to extents
2 parents 5ee9568 + 5637552 commit 9223295

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

LoopProjectFile/Extents.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def CheckExtentsValid(rootGroup, xyzGridSize, verbose=False):
2424
2525
"""
2626
valid = True
27+
if ("epsg" in rootGroup.ncattrs()):
28+
if verbose:
29+
print(" ", rootGroup.epsg)
30+
else:
31+
print("(INVALID) No epsg format in project file")
32+
valid = False
33+
2734
# Check Projection Model
2835
if "workingFormat" in rootGroup.ncattrs():
2936
if verbose:
@@ -127,10 +134,13 @@ def GetExtents(rootGroup):
127134
Returns
128135
-------
129136
dict {"errorFlag", "errorString"/"value"}
130-
value is a dict{"geodesic":[double, double, double, double],
131-
"utm":[int, int, double, double, double, double], "depth":[double, double],
132-
"spacing":[double, double, double]} containing the extents of this
133-
project file
137+
value is a dict{
138+
"geodesic":[double, double, double, double],
139+
"utm":[int, int, double, double, double, double],
140+
"depth":[double, double],
141+
"spacing":[double, double, double],
142+
"epsg":str
143+
} containing the extents of this project file
134144
135145
"""
136146
response = {"errorFlag": False}
@@ -150,6 +160,7 @@ def GetExtents(rootGroup):
150160
errStr = "(ERROR) No or incomplete geodesic boundary in loop project file"
151161
print(errStr)
152162
response = {"errorFlag": True, "errorString": errStr}
163+
153164
if (
154165
"utmZone" in rootGroup.ncattrs()
155166
and "utmNorthSouth" in rootGroup.ncattrs()
@@ -170,12 +181,14 @@ def GetExtents(rootGroup):
170181
errStr = "(ERROR) No or incomplete UTM boundary in loop project file"
171182
print(errStr)
172183
response = {"errorFlag": True, "errorString": errStr}
184+
173185
if "topDepth" in rootGroup.ncattrs() and "bottomDepth" in rootGroup.ncattrs():
174186
depth = [rootGroup.bottomDepth, rootGroup.topDepth]
175187
else:
176188
errStr = "(ERROR) No or incomplete depth boundary in loop project file"
177189
print(errStr)
178190
response = {"errorFlag": True, "errorString": errStr}
191+
179192
if (
180193
"spacingX" in rootGroup.ncattrs()
181194
and "spacingY" in rootGroup.ncattrs()
@@ -186,18 +199,27 @@ def GetExtents(rootGroup):
186199
errStr = "(ERROR) No or incomplete spacing data in loop project file"
187200
print(errStr)
188201
response = {"errorFlag": True, "errorString": errStr}
202+
203+
if ("epsg" in rootGroup.ncattrs()):
204+
epsg = rootGroup.epsg
205+
else:
206+
errStr = "(ERROR) No or incomplete epsg data in loop project file"
207+
print(errStr)
208+
response = {"errorFlag": True, "errorString": errStr}
209+
189210
if response["errorFlag"] is False:
190211
response["value"] = {
191212
"geodesic": geodesic,
192213
"utm": utm,
193214
"depth": depth,
194215
"spacing": spacing,
216+
"epsg": epsg
195217
}
196218
return response
197219

198220

199221
# Set extents of region of interest on root group
200-
def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
222+
def SetExtents(rootGroup, geodesic, utm, depth, spacing, epsg, preference="utm"):
201223
"""
202224
**SetExtents** - Saves the extents of the region of interest as specified into
203225
the netCDF Loop Project File
@@ -220,6 +242,9 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
220242
preference: string (optional)
221243
A string ("utm" or "geodesic") which specifies which format the Loop GUI
222244
region of interest should be displayed
245+
epsg: string
246+
A string of the EPSG projection used in the Loop Project in the
247+
format "EPSG:<value>"
223248
224249
Returns
225250
-------
@@ -273,6 +298,7 @@ def SetExtents(rootGroup, geodesic, utm, depth, spacing, preference="utm"):
273298
rootGroup.spacingY = spacing[1]
274299
rootGroup.spacingZ = spacing[2]
275300
rootGroup.workingFormat = 1 if preference == "utm" else 0
301+
rootGroup.epsg = epsg
276302

277303
# Do a quick sanity check and swap min and max values if wrong
278304
if rootGroup.minLatitude > rootGroup.maxLatitude:

LoopProjectFile/LoopProjectFile.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def Set(filename, element, **kwargs):
165165
"depth" = [topDepth, bottomDepth]
166166
"spacing" = [E/WSpacing, N/SSpacing, DepthSpacing]
167167
"preference" = "utm" or "geodesic" (optional)
168+
"epsg" = EPSG projection used
168169
strModel : "data" = the 3D scalar field of structural data
169170
"index" = the index of the dataset to save
170171
"verbose" = optional extra console logging
@@ -195,7 +196,7 @@ def Set(filename, element, **kwargs):
195196
For saving extents (in the middle of the pacific ocean):
196197
>>> LoopProjectFile.Set("test.loop3d", "extents", geodesic=[0,1,-180,-179], \
197198
utm=[1,1,10000000,9889363.77,833966.132,722587.169], depth=[-1000,-2000] \
198-
spacing=[1000,1000,10], preference="utm")
199+
spacing=[1000,1000,10], preference="utm", epsg="EPSG:32753")
199200
200201
For saving field observations:
201202
>>> data = ((easting, northing, altitude), dipdir, dip, polarity, formation, layer) * X rows
@@ -344,7 +345,8 @@ def Get(filename, element, **kwargs):
344345
"utm" = [utmZone, utmNorthSouth, minNorthing, maxNorthing, minEasting, maxEasting]
345346
"depth" = [topDepth, bottomDepth]
346347
"spacing" = [N/SSpacing, E/WSpacing, DepthSpacing]
347-
"preference" = "utm" or "geodesic" (optional)}
348+
"preference" = "utm" or "geodesic" (optional),
349+
"epsg" = EPSG projection}
348350
strModel : "value" = the 3D scalar field of structural data
349351
350352
Examples
@@ -368,6 +370,7 @@ def Get(filename, element, **kwargs):
368370
>>> utm = data["utm"]
369371
>>> depth = data["depth"]
370372
>>> spacing = data["spacing"]
373+
>>> epsg = data["epsg"]
371374
372375
Parameters
373376
----------

0 commit comments

Comments
 (0)