/** * Creates a JTS polygon based on zone definition. * * @param zone * @return */ public static Polygon createPolygonForZone(IZone zone) { return createPolygonForLocations(zone.getBounds()); }
/** * Create a copy of an SPI object. Used by web services for marshaling. * * @param input * @return */ public static Zone copy(IZone input) throws SiteWhereException { Zone result = new Zone(); result.setId(input.getId()); result.setToken(input.getToken()); result.setAreaId(input.getAreaId()); result.setName(input.getName()); result.setCreatedDate(input.getCreatedDate()); result.setBorderColor(input.getBorderColor()); result.setFillColor(input.getFillColor()); result.setOpacity(input.getOpacity()); result.setBounds(Location.copy(input.getBounds())); PersistentEntity.copy(input, result); return result; } }
/** * Convert zone from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GZone asGrpcZone(IZone api) throws SiteWhereException { GZone.Builder grpc = GZone.newBuilder(); grpc.setName(api.getName()); grpc.addAllBounds(CommonModelConverter.asGrpcLocations(api.getBounds())); grpc.setFillColor(api.getFillColor()); grpc.setBorderColor(api.getBorderColor()); grpc.setOpacity(api.getOpacity()); grpc.setEntityInformation(CommonModelConverter.asGrpcEntityInformation(api)); return grpc.build(); }
/** * Copy information from SPI into Mongo {@link Document}. * * @param source * @param target */ public static void toDocument(IZone source, Document target) { target.append(PROP_AREA_ID, source.getAreaId()); target.append(PROP_NAME, source.getName()); target.append(PROP_BORDER_COLOR, source.getBorderColor()); target.append(PROP_FILL_COLOR, source.getFillColor()); target.append(PROP_OPACITY, source.getOpacity()); MongoBoundedEntity.saveBounds(source, target); MongoPersistentEntity.toDocument(source, target); }
public <T extends IZone> ZoneMatcher(IDeviceLocation location, List<T> zones) { this.location = location; for (IZone zone : zones) { Polygon zonePoly = GeoUtils.createPolygonForZone(zone); ZoneContainment containment = (zonePoly.contains(GeoUtils.createPointForLocation(location))) ? ZoneContainment.Inside : ZoneContainment.Outside; ZoneRelationship relationship = new ZoneRelationship(location, zone, containment); relationships.put(zone.getToken(), relationship); } }