added methods for check if point in polygon to tbel
This commit is contained in:
parent
d4f7cb7df1
commit
e2fdc5a4ba
@ -215,6 +215,7 @@ public class DefaultTbActorSystem implements TbActorSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
actors.values().forEach(mailbox -> Optional.ofNullable(mailbox).ifPresent(m -> m.destroy(null)));
|
||||||
dispatchers.values().forEach(dispatcher -> {
|
dispatchers.values().forEach(dispatcher -> {
|
||||||
dispatcher.getExecutor().shutdown();
|
dispatcher.getExecutor().shutdown();
|
||||||
try {
|
try {
|
||||||
@ -226,7 +227,6 @@ public class DefaultTbActorSystem implements TbActorSystem {
|
|||||||
if (scheduler != null) {
|
if (scheduler != null) {
|
||||||
scheduler.shutdownNow();
|
scheduler.shutdownNow();
|
||||||
}
|
}
|
||||||
actors.values().forEach(mailbox -> Optional.ofNullable(mailbox).ifPresent(m -> m.destroy(null)));
|
|
||||||
actors.clear();
|
actors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,10 @@
|
|||||||
<groupId>org.thingsboard.common</groupId>
|
<groupId>org.thingsboard.common</groupId>
|
||||||
<artifactId>util</artifactId>
|
<artifactId>util</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.thingsboard.rule-engine</groupId>
|
||||||
|
<artifactId>rule-engine-components</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javadelight</groupId>
|
<groupId>org.javadelight</groupId>
|
||||||
<artifactId>delight-nashorn-sandbox</artifactId>
|
<artifactId>delight-nashorn-sandbox</artifactId>
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.script.api.tbel;
|
package org.thingsboard.script.api.tbel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
@ -23,6 +24,10 @@ import org.mvel2.ParserConfiguration;
|
|||||||
import org.mvel2.execution.ExecutionArrayList;
|
import org.mvel2.execution.ExecutionArrayList;
|
||||||
import org.mvel2.execution.ExecutionHashMap;
|
import org.mvel2.execution.ExecutionHashMap;
|
||||||
import org.mvel2.util.MethodStub;
|
import org.mvel2.util.MethodStub;
|
||||||
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
|
import org.thingsboard.rule.engine.geo.Coordinates;
|
||||||
|
import org.thingsboard.rule.engine.geo.GeoUtil;
|
||||||
|
import org.thingsboard.rule.engine.geo.RangeUnit;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -371,6 +376,10 @@ public class TbUtils {
|
|||||||
byte[].class, int.class)));
|
byte[].class, int.class)));
|
||||||
parserConfig.addImport("parseBinaryArrayToInt", new MethodStub(TbUtils.class.getMethod("parseBinaryArrayToInt",
|
parserConfig.addImport("parseBinaryArrayToInt", new MethodStub(TbUtils.class.getMethod("parseBinaryArrayToInt",
|
||||||
byte[].class, int.class, int.class)));
|
byte[].class, int.class, int.class)));
|
||||||
|
parserConfig.addImport("isInsidePolygon", new MethodStub(TbUtils.class.getMethod("isInsidePolygon",
|
||||||
|
double.class, double.class, String.class)));
|
||||||
|
parserConfig.addImport("isInsideCircle", new MethodStub(TbUtils.class.getMethod("isInsideCircle",
|
||||||
|
double.class, double.class, String.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String btoa(String input) {
|
public static String btoa(String input) {
|
||||||
@ -1437,6 +1446,22 @@ public class TbUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isInsidePolygon(double latitude, double longitude, String perimeter) {
|
||||||
|
return GeoUtil.contains(perimeter, new Coordinates(latitude, longitude));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isInsideCircle(double latitude, double longitude, String perimeter) {
|
||||||
|
JsonNode perimeterJson = JacksonUtil.toJsonNode(perimeter);
|
||||||
|
double centerLatitude = Double.parseDouble(perimeterJson.get("latitude").asText());
|
||||||
|
double centerLongitude = Double.parseDouble(perimeterJson.get("longitude").asText());
|
||||||
|
double range = Double.parseDouble(perimeterJson.get("radius").asText());
|
||||||
|
RangeUnit rangeUnit = perimeterJson.has("radiusUnit") ? RangeUnit.valueOf(perimeterJson.get("radiusUnit").asText()) : RangeUnit.METER;
|
||||||
|
|
||||||
|
Coordinates entityCoordinates = new Coordinates(latitude, longitude);
|
||||||
|
Coordinates perimeterCoordinates = new Coordinates(centerLatitude, centerLongitude);
|
||||||
|
return range > GeoUtil.distance(entityCoordinates, perimeterCoordinates, rangeUnit);
|
||||||
|
}
|
||||||
|
|
||||||
private static byte isValidIntegerToByte(Integer val) {
|
private static byte isValidIntegerToByte(Integer val) {
|
||||||
if (val > 255 || val < -128) {
|
if (val > 255 || val < -128) {
|
||||||
throw new NumberFormatException("The value '" + val + "' could not be correctly converted to a byte. " +
|
throw new NumberFormatException("The value '" + val + "' could not be correctly converted to a byte. " +
|
||||||
|
|||||||
@ -1245,6 +1245,56 @@ const tbelEditorCompletions:TbEditorCompletions = {
|
|||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
isInsidePolygon: {
|
||||||
|
meta: 'function',
|
||||||
|
description: 'Checks if a given point is inside a polygon.',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: 'latitude',
|
||||||
|
description: 'The latitude of the point',
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'longitude',
|
||||||
|
description: 'The longitude of the point',
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'perimeter',
|
||||||
|
description: 'The polygon perimeter represented as a string',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
return: {
|
||||||
|
description: 'True if the point is inside the polygon, false otherwise.',
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isInsideCircle: {
|
||||||
|
meta: 'function',
|
||||||
|
description: 'Checks if a given point is inside a circular area.',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: 'latitude',
|
||||||
|
description: 'The latitude of the point',
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'longitude',
|
||||||
|
description: 'The longitude of the point',
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'perimeter',
|
||||||
|
description: 'A string representation of the circle, containing center coordinates and radius',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
return: {
|
||||||
|
description: 'True if the point is inside the circle, false otherwise.',
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const tbelUtilsAutocompletes = new TbEditorCompleter(tbelEditorCompletions);
|
export const tbelUtilsAutocompletes = new TbEditorCompleter(tbelEditorCompletions);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user