8000 608 - Allow import of SHP geometries by bferguso · Pull Request #3 · bcgov/arches · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Dismiss alert

608 - Allow import of SHP geometries #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: stable/7.5.2.2_bcgov_10987
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions arches/app/media/js/viewmodels/map-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ define([
'geojson-extent',
'geojsonhint',
'togeojson',
'shpjsesm',
'proj4',
'views/components/map',
'views/components/cards/select-feature-layers',
'views/components/datatypes/geojson-feature-collection',
], function($, _, ko, koMapping, arches, uuid, geojsonExtent, geojsonhint, toGeoJSON, proj4, MapComponentViewModel, selectFeatureLayersFactory) {
], function($, _, ko, koMapping, arches, uuid, geojsonExtent, geojsonhint, toGeoJSON, shpjs, proj4, MapComponentViewModel, selectFeatureLayersFactory) {
var viewModel = function(params) {


var self = this;
var padding = 40;
var drawFeatures;

var resourceId = params.tile ? params.tile.resourceinstance_id : '';
if (this.widgets === undefined) { // could be [], so checking specifically for undefined
this.widgets = params.widgets || [];
Expand Down Expand Up @@ -620,7 +621,7 @@ define([
var promises = [];
for (var i = 0; i < files.length; i++) {
var extension = files[i].name.split('.').pop();
if (!['kml', 'json', 'geojson'].includes(extension)) {
if (!['kml', 'json', 'geojson','shp','zip'].includes(extension)) {
errors.push({
message: 'File unsupported: "' + files[i].name + '"'
});
Expand All @@ -629,18 +630,35 @@ define([
var file = files[i];
var extension = file.name.split('.').pop();
var reader = new window.FileReader();
reader. {
reader. class="x x-first x-last"> (e) {
var geoJSON;
if (['json', 'geojson'].includes(extension))
geoJSON = JSON.parse(e.target.result);
else
else if (extension === 'kml')
geoJSON = toGeoJSON.kml(
new window.DOMParser()
.parseFromString(e.target.result, "text/xml")
);
resolve(geoJSON);
else if (extension === 'shp')
geoJSON = {"type": "FeatureCollection", "features":
shpjs.parseShp(e.target.result).reduce(function(features, geometry) {
features = features.concat({"type": "Feature", "geometry": geometry, "properties": {}});
return features;
}, [])}

else if (extension === 'zip')
shpjs.parseZip(e.target.result).then(function(parsedZip) {
resolve(parsedZip);
});
if (extension !== 'zip')
resolve(geoJSON);
};
reader.readAsText(file);
if (["shp", "zip"].includes(extension)) {
reader.readAsArrayBuffer(file);
} else
{
reader.readAsText(file);
}
}));
}
}
Expand Down
8 changes: 8 additions & 0 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from arches.app.search.search_engine_factory import SearchEngineInstance as se
from arches.app.search.mappings import TERMS_INDEX, RESOURCES_INDEX
from arches.app.search.elasticsearch_dsl_builder import Query, Bool, Terms, Nested
from arches.app.search.custom_resource_search import CustomResourceSearchValue
from arches.app.tasks import index_resource
from arches.app.utils import import_class_from_string, task_management
from arches.app.utils.label_based_graph import LabelBasedGraph
Expand All @@ -59,6 +60,7 @@


class Resource(models.ResourceInstance):

class Meta:
proxy = True

Expand Down Expand Up @@ -482,6 +484,12 @@ def get_documents_to_index(self, fetchTiles=True, datatype_factory=None, node_da
},
}
)

if CustomResourceSearchValue.has_custom_search_class():
CustomResourceSearchValue.get_custom_search_class().add_search_terms(
self, document, terms
)

return document, terms

def delete(self, user={}, index=True, transaction_id=None):
Expand Down
7 changes: 7 additions & 0 deletions arches/app/search/components/term_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from arches.app.utils.betterJSONSerializer import JSONDeserializer
from arches.app.search.elasticsearch_dsl_builder import Bool, Ids, Match, Nested, SimpleQueryString, QueryString, Terms, Term
from arches.app.search.components.base import BaseSearchFilter
from arches.app.search.custom_resource_search import CustomResourceSearchValue

details = {
"searchcomponentid": "",
Expand Down Expand Up @@ -81,6 +82,12 @@ def append_dsl(self, search_results_object, permitted_nodegroups, include_provis
else:
search_query.filter(nested_conceptid_filter)

# Add additional search query if configured
if CustomResourceSearchValue.has_custom_search_class():
CustomResourceSearchValue.get_custom_search_class().add_search_filter(
search_query, term
)

search_results_object["query"].add_query(search_query)


Expand Down
76 changes: 76 additions & 0 deletions arches/app/search/custom_resource_search.py
9E7A
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from arches.app.models.system_settings import settings
from arches.app.utils import import_class_from_string


class CustomResourceSearchValue:
"""
Base class for creating custom sections in the Resource Instance elasticsearch document.
"""

custom_search_path = "custom_values"

def __init__(self):
pass

@staticmethod
def has_custom_search_class():
return CustomResourceSearchValue.get_custom_search_class() is not None

@staticmethod
def get_custom_search_class():
return (
import_class_from_string(settings.CUSTOM_SEARCH_CLASS)
if settings.setting_exists("CUSTOM_SEARCH_CLASS")
and settings.CUSTOM_SEARCH_CLASS
else None
)

@staticmethod
def get_custom_search_path():
"""
Identifies the document key where the custom ES document section is located.

:return: ES document key
:rtype String
"""
return CustomResourceSearchValue.custom_search_path

@staticmethod
def add_search_terms(resourceinstance, document, terms):
"""
Adds the custom ES search document section for the resource instance.
:param resourceinstance: resource instance being indexed
:param document: Original ES document for the Resource Instance
:param terms: ES terms in the document
"""
pass

@staticmethod
def add_search_filter(search_query, term):
"""
Adds to or modifies the term search_query to include the custom search document section as part of the search
:param search_query: The original search term query
:param term: The search term
"""
pass

@staticmethod
def get_custom_search_config():
"""
Defines the ES structure of the custom search document section. Called when the initial ES resources index is created.

:return: dict of the custom document section
:rtype dict
"""
return {
"type": "nested",
"properties": {
"custom_value": {
"type": "text",
"fields": {
"raw": {"type": "keyword", "ignore_above": 256},
"folded": {"type": "text", "analyzer": "folding"},
},
}
},
}
Loading
Loading
0