Skip to content

Commit

Permalink
capability to store point as boundingpolygon
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Apr 14, 2021
1 parent 489a7df commit 79720c1
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<xsl:with-param name="subTreeSnippet">

<xsl:variable name="geometry">
<xsl:apply-templates select="gex:polygon/gml:MultiSurface|gex:polygon/gml:LineString"
<xsl:apply-templates select="gex:polygon/gml:MultiSurface|gex:polygon/gml:LineString|gex:polygon/gml:Point"
mode="gn-element-cleaner"/>
</xsl:variable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@
</description>
</element>
<element name="gex:EX_BoundingPolygon" id="341.0">
<label>Bounding Polygon</label>
<label>Bounding geometry</label>
<description>Boundary enclosing the dataset, expressed as the closed set of
(x,y)
coordinates of the polygon (last point replicates first point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
<!-- Add required gml attributes if missing -->
<xsl:template match="gml:Polygon[not(@gml:id) and not(@srsName)]|
gml:MultiSurface[not(@gml:id) and not(@srsName)]|
gml:Point[not(@gml:id) and not(@srsName)]|
gml:LineString[not(@gml:id) and not(@srsName)]">
<xsl:copy>
<xsl:attribute name="gml:id">
Expand Down
4 changes: 2 additions & 2 deletions schemas/iso19139/src/main/plugin/iso19139/extract-gml.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
-->
<xsl:for-each select="gmd:polygon/(gml:*|gml320:*)[
local-name() != 'MultiCurve' and
count(*) > 0 and
.//(gml:posList|gml320:posList) != '']">
count(*) > 0 and (
.//(gml:posList|gml320:posList) != '' or .//(gml:pos|gml320:pos) != '')]">
<xsl:copy-of copy-namespaces="no" select="."/>
</xsl:for-each>
</xsl:template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@
<xsl:with-param name="subTreeSnippet">

<xsl:variable name="geometry">
<xsl:apply-templates select="gmd:polygon/gml:MultiSurface|gmd:polygon/gml:LineString|
gmd:polygon/gml320:MultiSurface|gmd:polygon/gml320:LineString"
<xsl:apply-templates select="gmd:polygon/gml:MultiSurface|gmd:polygon/gml:LineString|gmd:polygon/gml:Point|
gmd:polygon/gml320:MultiSurface|gmd:polygon/gml320:LineString|gmd:polygon/gml320:Point"
mode="gn-element-cleaner"/>
</xsl:variable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
</description>
</element>
<element name="gmd:EX_BoundingPolygon" id="341.0">
<label>Bounding Polygon</label>
<label>Bounding geometry</label>
<description>Boundary enclosing the dataset, expressed as the closed set of (x,y)
coordinates of the polygon (last point replicates first point)
</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
</description>
</element>
<element name="gmd:EX_BoundingPolygon" id="341.0">
<label>Bounding Polygon</label>
<label>Bounding geometry</label>
<description>Boundary enclosing the dataset, expressed as the closed
set of (x,y)
coordinates of the polygon (last point replicates first point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
</description>
</element>
<element name="gmd:EX_BoundingPolygon" id="341.0">
<label>Bounding Polygon</label>
<label>Bounding geometry</label>
<description>Boundary enclosing the dataset, expressed as the closed set of (x,y)
coordinates of the polygon (last point replicates first point)
</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@
<xsl:template match="gml:Polygon[not(@gml:id) or not(@srsName)]|
gml:MultiSurface[not(@gml:id) or not(@srsName)]|
gml:LineString[not(@gml:id) or not(@srsName)]|
gml:Point[not(@gml:id) or not(@srsName)]|
gml320:Polygon[not(@gml320:id) or not(@srsName)]|
gml320:MultiSurface[not(@gml:id) or not(@srsName)]|
gml320:LineString[not(@gml:id) or not(@srsName)]">
gml320:LineString[not(@gml:id) or not(@srsName)]|
gml320:Point[not(@gml320:id) or not(@srsName)]">
<xsl:element name="gml:{local-name()}"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@
'$http',
'gnMap',
'gnMapsManager',
'olDecorateInteraction',
'gnGeometryService',
function BoundingPolygonController(
$scope,
$attrs,
$http,
gnMap,
gnMapsManager,
olDecorateInteraction,
gnGeometryService) {
$scope,
$attrs,
$http,
gnMap,
gnMapsManager,
gnGeometryService) {
var ctrl = this;

// set read only
Expand All @@ -83,21 +81,13 @@
ctrl.initValue();
});

// interactions with map
// Get interaction layer
var layer = gnGeometryService.getCommonLayer(ctrl.map);
var source = layer.getSource();

ctrl.drawInteraction = new ol.interaction.Draw({
type: 'MultiPolygon',
source: source
});
ctrl.drawLineInteraction = new ol.interaction.Draw({
type: 'LineString',
source: source
});
ctrl.modifyInteraction = new ol.interaction.Modify({
features: source.getFeaturesCollection()
});
// Draw interaction variables
var activeDrawInteraction;
ctrl.activeDrawType = null;

// this is used to deactivate zoom on draw end
ctrl.zoomInteraction = null;
Expand All @@ -107,26 +97,12 @@
}
});

// add our layer&interactions to the map
olDecorateInteraction(ctrl.drawInteraction);
olDecorateInteraction(ctrl.drawLineInteraction);
olDecorateInteraction(ctrl.modifyInteraction);
ctrl.drawInteraction.active = false;
ctrl.drawLineInteraction.active = false;
ctrl.modifyInteraction.active = false;

// add interactions to map
ctrl.map.addInteraction(ctrl.drawInteraction);
ctrl.map.addInteraction(ctrl.drawLineInteraction);
ctrl.map.addInteraction(ctrl.modifyInteraction);

// clear existing features on draw end & save feature
// Clear existing features on draw end & save feature
function handleDrawEnd(event) {
clearActiveDrawInteraction();
ctrl.fromTextInput = false;
source.clear(event.feature);
ctrl.updateOutput(event.feature);
ctrl.drawInteraction.active = false;
ctrl.drawLineInteraction.active = false;
$scope.$digest();

// prevent interference by zoom interaction
Expand All @@ -138,15 +114,45 @@
}, 251);
}
}
ctrl.drawInteraction.on('drawend', handleDrawEnd);
ctrl.drawLineInteraction.on('drawend', handleDrawEnd);

// update output on modify end
ctrl.modifyInteraction.on('modifyend', function(event) {
// Update text field when geometry has modified
function handleModifyEnd(event) {
ctrl.fromTextInput = false;
ctrl.updateOutput(event.features.item(0));
$scope.$digest();
});
}

// Removes event handler from current draw interaction and
// removes interaction from map. Clears interaction variables.
function clearActiveDrawInteraction() {
if (!activeDrawInteraction) return;
activeDrawInteraction.un('drawend', handleDrawEnd);
ctrl.map.removeInteraction(activeDrawInteraction);
activeDrawInteraction = null;
ctrl.activeDrawType = null;
}

// Add new draw interaction based on given geometry type name.
// Also add event handler that fires when drawing ends.
ctrl.setActiveDrawInteraction = function(geometryType) {
clearActiveDrawInteraction();
activeDrawInteraction = new ol.interaction.Draw({
source: source,
type: geometryType
});
activeDrawInteraction.on('drawend', handleDrawEnd);
ctrl.map.addInteraction(activeDrawInteraction);
ctrl.activeDrawType = geometryType;
}

// Add modify interaction (always active when not readOnly)
if (!ctrl.readOnly) {
var modifyInteraction = new ol.interaction.Modify({
features: source.getFeaturesCollection()
});
modifyInteraction.on('modifyend', handleModifyEnd);
ctrl.map.addInteraction(modifyInteraction);
}

// output for editor (equals input by default)
ctrl.outputPolygonXml = surroundGmlWithGmdPolygon(ctrl.polygonXml);
Expand All @@ -157,8 +163,6 @@
ctrl.dataProjection = 'EPSG:4326';

// available input formats
// GML is not available as it cannot be parsed
// without namespace info
ctrl.formats = ['WKT', 'GeoJSON', 'GML'];
ctrl.currentFormat = ctrl.formats[0];

Expand All @@ -169,13 +173,37 @@
}
}
return false;
};
}

/**
* Calculates an enlarged extent for the given feature.
* For polygons and lines, the extent will be twice the size of its smallest dimension.
* For point features, the extent will be 1 square decimal degree, centered around the point.
* If needed, the LL point extent will be reprojected to fit the map projection.
*
* @param {ol.feature} feature Input feature for which to return an enlarged extent
* @returns {Array.<number>} Enlarged extent
*/
function getEnlargedExtent(feature) {

var extent = feature.getGeometry().getExtent();
var buffer = Math.min.apply(ol.extent.getSize(extent)) * 0.1;
return ol.extent.buffer(extent, buffer);
};

// Get buffer distance of 50% of the smallest extent dimension (width or height)
var buffer = Math.min.apply(null, ol.extent.getSize(extent)) * 0.5;

if (buffer > 0) {
// Feature has a size: apply calculated buffer
return ol.extent.buffer(extent, buffer);
} else {
// Feature probably is a point, causing the extent to have 0 width and height:
// Get the extent center (= point), reproject to LL, buffer by 0.5 dd,
// reproject new extent back to map projection and return it
var mapProj = ctrl.map.getView().getProjection();
var center = ol.proj.toLonLat(ol.extent.getCenter(extent), mapProj);
extent = ol.extent.buffer(ol.extent.boundingExtent([center, center]), 0.5);
return ol.proj.transformExtent(extent, 'EPSG:4326', mapProj, 8);
}
}

// parse initial input coordinates to display shape
ctrl.initValue = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
<!-- draw tool & select boxes -->
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-push-6" ng-if="!ctrl.readOnly">
<label class="text-muted control-label" translate>drawOnMap</label>
<br />
<div gi-btn-group>
<div class="btn-group">
<div class="btn-group">
<button class="btn btn-default btn-warning"
gi-btn="active" ng-model="ctrl.drawInteraction.active">
<span class="fa fa-pencil"></span>&nbsp;
<span translate>Polygon</span>
</button>
<button class="btn btn-default btn-warning"
gi-btn="active" ng-model="ctrl.drawLineInteraction.active">
<span class="fa fa-pencil"></span>&nbsp;
<span translate>Line</span>
</button>
</div>
</div>
<button class="btn btn-default btn-warning"
gi-btn="active" ng-model="ctrl.modifyInteraction.active">
<div class="pull-right">
<label class="text-muted control-label" translate>drawOnMap</label>
<br />
<button class="btn btn-default btn-warning pull-left gn-margin-right"
ng-click="ctrl.setActiveDrawInteraction('MultiPolygon')"
ng-class="{'active': ctrl.activeDrawType === 'MultiPolygon'}">
<span class="fa fa-pencil"></span>&nbsp;
<span translate>Polygon</span>
</button>
<button class="btn btn-default btn-warning pull-left gn-margin-right"
ng-click="ctrl.setActiveDrawInteraction('LineString')"
ng-class="{'active': ctrl.activeDrawType === 'LineString'}">
<span class="fa fa-pencil"></span>&nbsp;
<span translate>Line</span>
</button>
<button class="btn btn-default btn-warning pull-left"
ng-click="ctrl.setActiveDrawInteraction('Point')"
ng-class="{'active': ctrl.activeDrawType === 'Point'}">
<span class="fa fa-pencil"></span>&nbsp;
<span translate>modifyGeometry</span>
<span translate>Point</span>
</button>
</div>
</div>
Expand All @@ -39,15 +38,15 @@
<div class="flex-row width-100">
<div class="flex-nogrow">
<select ng-model="ctrl.currentFormat"
ng-options="format for format in ctrl.formats"
ng-change="ctrl.handleInputOptionsChange()">
ng-options="format for format in ctrl.formats"
ng-change="ctrl.handleInputOptionsChange()">
</select>
</div>
<div class="flex-spacer"></div>
<div class="flex-shrink">
<select ng-model="ctrl.currentProjection"
ng-options="proj.code as proj.label for proj in ctrl.projections"
ng-change="ctrl.handleInputOptionsChange()">
ng-options="proj.code as proj.label for proj in ctrl.projections"
ng-change="ctrl.handleInputOptionsChange()">
</select>
</div>
</div>
Expand All @@ -56,7 +55,7 @@

<div class="spacer" />

<div ng-if="ctrl.dataOlProjection == null" class="alert alert-danger"
<div ng-if="ctrl.polygonXml && ctrl.dataOlProjection == null" class="alert alert-danger"
data-translate=""
data-translate-values="{srsName:'{{ctrl.dataProjection}}'}">
badGmlProjectionCode
Expand All @@ -66,29 +65,29 @@
<div class="row">
<div class="col-md-12">
<div class="has-feedback"
ng-class="{ 'has-success': ctrl.fromTextInput && !ctrl.parseError, 'has-error': ctrl.parseError }">
ng-class="{ 'has-success': ctrl.fromTextInput && !ctrl.parseError, 'has-error': ctrl.parseError }">
<label class="text-muted control-label" translate>inputGeometryText</label>
<textarea class="form-control" rows="4" ng-model="ctrl.inputGeometry"
ng-model-options="{ debounce: 300 }"
placeholder="{{'inputGeometryText' | translate}}"
ng-change="ctrl.handleInputChange()"
ng-readonly="ctrl.readOnly"/>
ng-model-options="{ debounce: 300 }"
placeholder="{{'inputGeometryText' | translate}}"
ng-change="ctrl.handleInputChange()"
ng-readonly="ctrl.readOnly"/>
<small class="text-danger"
ng-show="ctrl.fromTextInput && ctrl.parseError">
ng-show="ctrl.fromTextInput && ctrl.parseError">
{{ 'inputGeometryIsInvalid' | translate}} {{ctrl.parseError}}</small>
<small class="text-success"
ng-show="ctrl.fromTextInput && !ctrl.parseError" translate>
ng-show="ctrl.fromTextInput && !ctrl.parseError" translate>
inputGeometryIsValid</small>
<small class="text-muted"
ng-show="!ctrl.fromTextInput && !ctrl.readOnly" translate>
ng-show="!ctrl.fromTextInput && !ctrl.readOnly" translate>
inputGeometryHint</small>
<small class="text-muted"
ng-show="ctrl.readOnly" translate>
ng-show="ctrl.readOnly" translate>
inputGeometryReadOnlyHint</small>
</div>
</div>
</div>

<!-- final output in GML -->
<input name="{{ctrl.identifier}}"
type="hidden" value="{{ctrl.outputPolygonXml}}"/>
type="hidden" value="{{ctrl.outputPolygonXml}}"/>
Loading

0 comments on commit 79720c1

Please sign in to comment.