Skip to content

Commit

Permalink
Fix circular import issues in ogc module
Browse files Browse the repository at this point in the history
  • Loading branch information
plstcharles committed Nov 6, 2019
1 parent 61ff339 commit b88917b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions thelper/data/geo/ogc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import tqdm

import thelper.data
import thelper.data.geo as geo
import thelper.train.utils
from thelper.data.geo.parsers import TileDataset, VectorCropDataset

logger = logging.getLogger(__name__)

Expand All @@ -25,7 +25,7 @@ class TB15D104:
LAKE_ID = 1


class TB15D104Dataset(geo.parsers.VectorCropDataset):
class TB15D104Dataset(VectorCropDataset):
"""OGC Testbed-15 dataset parser for D104 (lake/river) segmentation task."""

def __init__(self, raster_path, vector_path, px_size=None,
Expand Down Expand Up @@ -114,6 +114,7 @@ def lake_cropper(features, rasters_data, coverage, srs_target, px_size, skew, fe
srs_target_wkt = srs_target.ExportToWkt()

def crop_feature(feature):
import thelper.data.geo as geo
assert feature["clean"] # should not get here with bad features
roi, roi_tl, roi_br, crop_width, crop_height = \
geo.utils.get_feature_roi(feature["geometry"], px_size, skew, feature_buffer)
Expand Down Expand Up @@ -256,7 +257,7 @@ def __getitem__(self, idx):
return sample


class TB15D104TileDataset(geo.parsers.TileDataset):
class TB15D104TileDataset(TileDataset):
"""OGC Testbed-15 dataset parser for D104 (lake/river) segmentation task."""

def __init__(self, raster_path, vector_path, tile_size, tile_overlap,
Expand Down Expand Up @@ -288,6 +289,7 @@ def __getitem__(self, idx):
"""Returns the data sample (a dictionary) for a specific (0-based) index."""
if isinstance(idx, slice):
return self._getitems(idx)
import thelper.data.geo as geo
assert idx < len(self.samples), "sample index is out-of-range"
if idx < 0:
idx = len(self.samples) + idx
Expand Down Expand Up @@ -362,6 +364,7 @@ def report_geojson(self):
# here, we only care about reporting predictions, we ignore the (possibly missing) gt bboxes
import shapely
import geojson
import thelper.data.geo as geo
batch_size = len(self.bbox[0])
bbox_lists = [bboxes for batch in self.bbox for bboxes in batch] # one list per crop
if batch_size > 1:
Expand Down Expand Up @@ -392,6 +395,7 @@ def postproc_features(input_file, bboxes_srs, orig_geoms_path, output_file,
import json
import geojson
import shapely
import thelper.data.geo as geo
logger.debug("importing bboxes SRS...")
assert isinstance(bboxes_srs, (str, int, osr.SpatialReference)), \
"target EPSG SRS must be given as int/str"
Expand Down

0 comments on commit b88917b

Please sign in to comment.