Skip to content

Commit 8894e77

Browse files
committed
Import for geojson files containing a single feature
1 parent 46a26d3 commit 8894e77

4 files changed

Lines changed: 54 additions & 21 deletions

File tree

jigsawpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* JIGSAW: Interface to the JIGSAW meshing library.
1414
------------------------------------------------------------
1515
*
16-
* Last updated: 13 Aug., 2025
16+
* Last updated: 30 Aug., 2025
1717
*
1818
* Copyright 2019-2025
1919
* Darren Engwirda

jigsawpy/parse/loadgeo.py

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

2+
import warnings
23
import numpy as np
34
import json
45
import argparse
56

6-
from jigsawpy import jigsaw_msh_t, savemsh
7+
from jigsawpy.msh_t import jigsaw_msh_t
8+
from jigsawpy.savemsh import savemsh
79

810

911
def linegeo(line, nset, eset, nobj, last):
@@ -30,7 +32,13 @@ def linegeo(line, nset, eset, nobj, last):
3032

3133
last = last + npts
3234

33-
temp.vert2["coord"] = line[+0::]
35+
data = np.asarray(line)
36+
if (data.shape[1] > 2):
37+
warnings.warn("Z-COORD omitted", Warning)
38+
39+
# omit z if [x,y,z]
40+
temp.vert2["coord"][:, 0] = data[+0:, 0]
41+
temp.vert2["coord"][:, 1] = data[+0:, 1]
3442

3543
temp.edge2["index"][:, 0] = indx + 0
3644
temp.edge2["index"][:, 1] = indx + 1
@@ -75,7 +83,13 @@ def polygeo(loop, nset, eset, nobj, last):
7583

7684
last = last + npts
7785

78-
temp.vert2["coord"] = loop[:-1:]
86+
data = np.asarray(loop)
87+
if (data.shape[1] > 2):
88+
warnings.warn("Z-COORD omitted", Warning)
89+
90+
# omit z if [x,y,z]
91+
temp.vert2["coord"][:, 0] = data[:-1, 0]
92+
temp.vert2["coord"][:, 1] = data[:-1, 1]
7993

8094
temp.edge2["index"][:, 0] = idx1
8195
temp.edge2["index"][:, 1] = idx2
@@ -92,28 +106,28 @@ def readgeo(geom, nset, eset, nobj, last):
92106
93107
"""
94108

95-
if (geom["type"] == "LineString"):
109+
if (geom["type"].lower() == "linestring"):
96110

97111
line = geom["coordinates"]
98112

99113
nobj, last = linegeo(
100114
line, nset, eset, nobj, last)
101115

102-
elif (geom["type"] == "MultiLineString"):
116+
elif (geom["type"].lower() == "multilinestring"):
103117

104118
for line in geom["coordinates"]:
105119

106120
nobj, last = linegeo(
107121
line, nset, eset, nobj, last)
108122

109-
elif (geom["type"] == "Polygon"):
123+
elif (geom["type"].lower() == "polygon"):
110124

111125
for loop in geom["coordinates"]:
112126

113127
nobj, last = polygeo(
114128
loop, nset, eset, nobj, last)
115129

116-
elif (geom["type"] == "MultiPolygon"):
130+
elif (geom["type"].lower() == "multipolygon"):
117131

118132
for poly in geom["coordinates"]:
119133
for loop in poly:
@@ -124,6 +138,29 @@ def readgeo(geom, nset, eset, nobj, last):
124138
return nobj, last
125139

126140

141+
def readobj(feat, nset, eset, nobj, last):
142+
"""
143+
READOBJ: read a geoJSON feat into a jigsaw msh_t object.
144+
145+
"""
146+
147+
if (feat["type"].lower() != "geometrycollection"):
148+
149+
geom = feat["geometry"]
150+
151+
nobj, last = readgeo(
152+
geom, nset, eset, nobj, last)
153+
154+
else:
155+
156+
for geom in feat["geometries"]:
157+
158+
nobj, last = readgeo(
159+
geom, nset, eset, nobj, last)
160+
161+
return nobj, last
162+
163+
127164
def loadgeo(name, mesh):
128165
"""
129166
LOADGEO: load a geoJSON file into a jigsaw msh_t object.
@@ -140,21 +177,17 @@ def loadgeo(name, mesh):
140177

141178
with open(name) as f: geoj = json.load(f)
142179

143-
for feat in geoj["features"]:
144-
145-
geom = (feat["geometry"])
146-
147-
if (geom["type"] != "GeometryCollection"):
180+
if (geoj["type"].lower() != "featurecollection"):
148181

149-
nobj, last = readgeo(
150-
geom, nset, eset, nobj, last)
182+
nobj, last = readobj(
183+
geoj, nset, eset, nobj, last)
151184

152-
else:
185+
else:
153186

154-
for next in geom["geometries"]:
187+
for feat in geoj["features"]:
155188

156-
nobj, last = readgeo(
157-
next, nset, eset, nobj, last)
189+
nobj, last = readobj(
190+
feat, nset, eset, nobj, last)
158191

159192
mesh.vert2 = np.concatenate(nset, axis=0)
160193
mesh.edge2 = np.concatenate(eset, axis=0)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "jigsawpy"
7-
version = "1.1.0"
7+
version = "1.1.1"
88
description = "Python interface for the JIGSAW meshing library."
99
readme = "README.md"
1010
authors = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
AUTHOR = "Darren Engwirda"
1414
AUTHOR_EMAIL = "d.engwirda@gmail.com"
1515
URL = "https://github.com/dengwirda/"
16-
VERSION = "1.1.0"
16+
VERSION = "1.1.1"
1717
REQUIRES_PYTHON = ">=3.6.0"
1818
KEYWORDS = "Mesh-generation Delaunay Voronoi"
1919

0 commit comments

Comments
 (0)