Skip to content
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
25 changes: 15 additions & 10 deletions HqgisAlgorithm_geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def processAlgorithm(self, parameters, context, feedback):
# to uniquely identify the feature sink, and must be included in the
# dictionary returned by the processAlgorithm function.
source = self.parameterAsSource(parameters, self.INPUT, context)
addressField = self.parameterAsString(parameters, self.AddressField, context)
addressField = self.parameterAsString(
parameters, self.AddressField, context)
feedback.pushInfo(addressField)

# If source was not found, throw an exception to indicate that the algorithm
Expand Down Expand Up @@ -300,9 +301,13 @@ def processAlgorithm(self, parameters, context, feedback):
QgsCoordinateReferenceSystem(4326),
)

feedback.pushInfo("{} addresses to geocode".format(source.featureCount()))
feedback.pushInfo(
"{} addresses to geocode".format(
source.featureCount()))
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))
raise QgsProcessingException(
self.invalidSinkError(
parameters, self.OUTPUT))

total = 100.0 / source.featureCount() if source.featureCount() else 0
features = source.getFeatures()
Expand All @@ -315,16 +320,16 @@ def processAlgorithm(self, parameters, context, feedback):

# get the location from the API:
ApiUrl = (
"https://geocoder.ls.hereapi.com/search/6.2/geocode.json?apiKey="
+ creds["id"]
+ "&searchtext="
+ feature[addressField]
)
"https://geocoder.ls.hereapi.com/search/6.2/geocode.json?apiKey=" +
creds["id"] +
"&searchtext=" +
feature[addressField])
r = requests.get(ApiUrl)
print(ApiUrl)
try:
responseAddress = json.loads(r.text)["Response"]["View"][0]["Result"][0]
except:
responseAddress = json.loads(
r.text)["Response"]["View"][0]["Result"][0]
except BaseException:
feedback.pushWarning(
"unable to geocode feature {}: {}".format(
feature.id(), feature[addressField]
Expand Down
31 changes: 22 additions & 9 deletions HqgisAlgorithm_isochrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ def initAlgorithm(self, config=None):
# usually takes the form of a newly created vector layer when the
# algorithm is run in QGIS).
self.addParameter(
QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr("POI layer"))
)
QgsProcessingParameterFeatureSink(
self.OUTPUT,
self.tr("POI layer")))

def processAlgorithm(self, parameters, context, feedback):
"""
Expand All @@ -243,12 +244,21 @@ def processAlgorithm(self, parameters, context, feedback):
or source.wkbType() == 3004
):
raise QgsProcessingException("MultiPoint layer is not supported!")
transportMode = self.keys[self.parameterAsEnum(parameters, self.KEYS, context)]
mode = self.modes[self.parameterAsEnum(parameters, self.MODES, context)]
transportMode = self.keys[self.parameterAsEnum(
parameters, self.KEYS, context)]
mode = self.modes[self.parameterAsEnum(
parameters, self.MODES, context)]
slots = self.parameterAsString(parameters, self.DISTANCES, context)
metric = self.metric[self.parameterAsEnum(parameters, self.METRIC, context)]
departureTime = self.parameterAsString(parameters, self.DEPARTURETIME, context)
print(type(transportMode), type(metric), type(slots), type(mode), type(time))
metric = self.metric[self.parameterAsEnum(
parameters, self.METRIC, context)]
departureTime = self.parameterAsString(
parameters, self.DEPARTURETIME, context)
print(
type(transportMode),
type(metric),
type(slots),
type(mode),
type(time))
# feedback.pushInfo(addressField)

# If source was not found, throw an exception to indicate that the algorithm
Expand Down Expand Up @@ -284,7 +294,9 @@ def processAlgorithm(self, parameters, context, feedback):
# case we use the pre-built invalidSinkError method to return a standard
# helper text for when a sink cannot be evaluated
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))
raise QgsProcessingException(
self.invalidSinkError(
parameters, self.OUTPUT))

# Compute the number of steps to display within the progress bar and
# get features from source
Expand All @@ -296,7 +308,8 @@ def processAlgorithm(self, parameters, context, feedback):
if layerCRS != QgsCoordinateReferenceSystem(4326):
sourceCrs = source.sourceCrs()
destCrs = QgsCoordinateReferenceSystem(4326)
tr = QgsCoordinateTransform(sourceCrs, destCrs, QgsProject.instance())
tr = QgsCoordinateTransform(
sourceCrs, destCrs, QgsProject.instance())
for current, feature in enumerate(features):
# Stop the algorithm if cancel button has been clicked
if feedback.isCanceled():
Expand Down
3 changes: 2 additions & 1 deletion decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
]


PolylineHeader = namedtuple("PolylineHeader", "precision,third_dim,third_dim_precision")
PolylineHeader = namedtuple("PolylineHeader",
"precision,third_dim,third_dim_precision")


def decode(encoded):
Expand Down
Loading