Search in sources :

Example 21 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project hibernate-orm by hibernate.

the class GeometryEquality method testTypeAndVertexEquality.

protected boolean testTypeAndVertexEquality(Geometry geom1, Geometry geom2) {
    if (!geom1.getGeometryType().equals(geom2.getGeometryType())) {
        return false;
    }
    if (geom1.getNumGeometries() != geom2.getNumGeometries()) {
        return false;
    }
    if (geom1.getNumPoints() != geom2.getNumPoints()) {
        return false;
    }
    Coordinate[] coordinates1 = geom1.getCoordinates();
    Coordinate[] coordinates2 = geom2.getCoordinates();
    for (int i = 0; i < coordinates1.length; i++) {
        Coordinate c1 = coordinates1[i];
        Coordinate c2 = coordinates2[i];
        if (!testCoordinateEquality(c1, c2)) {
            return false;
        }
    }
    return true;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 22 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project graphhopper by graphhopper.

the class OSMShapeFileReader method getWayLength.

private double getWayLength(Coordinate start, List<Coordinate> pillars, Coordinate end) {
    double distance = 0;
    Coordinate previous = start;
    for (Coordinate point : pillars) {
        distance += distCalc.calcDist(lat(previous), lng(previous), lat(point), lng(point));
        previous = point;
    }
    distance += distCalc.calcDist(lat(previous), lng(previous), lat(end), lng(end));
    return distance;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 23 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project openremote by openremote.

the class ManagerDemoSetup method onStart.

@Override
public void onStart() throws Exception {
    KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
    Tenant masterTenant = keycloakDemoSetup.masterTenant;
    Tenant customerATenant = keycloakDemoSetup.customerATenant;
    masterRealmId = masterTenant.getId();
    customerARealmId = customerATenant.getId();
    // ################################ Demo assets for 'master' realm ###################################
    ServerAsset smartOffice = new ServerAsset();
    smartOffice.setRealmId(masterTenant.getId());
    smartOffice.setName("Smart Office");
    smartOffice.setLocation(geometryFactory.createPoint(new Coordinate(5.460315214821094, 51.44541688237109)));
    smartOffice.setType(BUILDING);
    List<AssetAttribute> smartOfficeAttributes = Arrays.asList(new AssetAttribute("geoStreet", STRING, Values.create("Torenallee 20")).setMeta(new MetaItem(LABEL, Values.create("Street")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoStreet"))), new AssetAttribute("geoPostalCode", AttributeType.NUMBER, Values.create(5617)).setMeta(new MetaItem(LABEL, Values.create("Postal Code")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoPostalCode"))), new AssetAttribute("geoCity", STRING, Values.create("Eindhoven")).setMeta(new MetaItem(LABEL, Values.create("City")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCity"))), new AssetAttribute("geoCountry", STRING, Values.create("Netherlands")).setMeta(new MetaItem(LABEL, Values.create("Country")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCountry"))));
    smartOffice.setAttributes(smartOfficeAttributes);
    smartOffice = assetStorageService.merge(smartOffice);
    smartOfficeId = smartOffice.getId();
    ServerAsset groundFloor = new ServerAsset("Ground Floor", FLOOR, smartOffice);
    groundFloor.setLocation(smartOffice.getLocation());
    groundFloor = assetStorageService.merge(groundFloor);
    groundFloorId = groundFloor.getId();
    ServerAsset lobby = new ServerAsset("Lobby", ROOM, groundFloor);
    lobby.setLocation(groundFloor.getLocation());
    lobby = assetStorageService.merge(lobby);
    lobbyId = lobby.getId();
    ServerAsset agent = new ServerAsset("Demo Agent", AGENT, lobby);
    agent.setLocation(lobby.getLocation());
    agent.setAttributes(initProtocolConfiguration(new AssetAttribute(agentProtocolConfigName), SimulatorProtocol.PROTOCOL_NAME).addMeta(new MetaItem(SimulatorProtocol.CONFIG_MODE, Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_DELAYED.toString())), new MetaItem(SimulatorProtocol.CONFIG_WRITE_DELAY_MILLISECONDS, Values.create(500))));
    agent = assetStorageService.merge(agent);
    agentId = agent.getId();
    ServerAsset thing = new ServerAsset("Demo Thing", THING, agent);
    thing.setLocation(agent.getLocation());
    thing.setAttributes(new AssetAttribute(thingLightToggleAttributeName, BOOLEAN, Values.create(true)).setMeta(new Meta(new MetaItem(LABEL, Values.create("Light 1 Toggle")), new MetaItem(DESCRIPTION, Values.create("Switch for living room light")), new MetaItem(STORE_DATA_POINTS, Values.create(true)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(SwitchSimulatorElement.ELEMENT_NAME)))), // No initial value!
    new AssetAttribute("light1Dimmer", PERCENTAGE).setMeta(new Meta(new MetaItem(LABEL, Values.create("Light 1 Dimmer")), new MetaItem(DESCRIPTION, Values.create("Dimmer for living room light")), new MetaItem(RANGE_MIN, Values.create(0)), new MetaItem(RANGE_MAX, Values.create(100)), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME_RANGE)), new MetaItem(SimulatorProtocol.CONFIG_MODE, Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_DELAYED.toString())))), new AssetAttribute("light1Color", COLOR_RGB, new ColorRGB(88, 123, 88).asArrayValue()).setMeta(new Meta(new MetaItem(LABEL, Values.create("Light 1 Color")), new MetaItem(DESCRIPTION, Values.create("Color of living room light")), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(ColorSimulatorElement.ELEMENT_NAME)))), new AssetAttribute("light1PowerConsumption", ENERGY_KWH, Values.create(12.345)).setMeta(new Meta(new MetaItem(LABEL, Values.create("Light 1 Usage")), new MetaItem(DESCRIPTION, Values.create("Total energy consumption of living room light")), new MetaItem(READ_ONLY, Values.create(true)), new MetaItem(FORMAT, Values.create("%3d kWh")), new MetaItem(AGENT_LINK, new AttributeRef(agent.getId(), agentProtocolConfigName).toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)), new MetaItem(STORE_DATA_POINTS, Values.create(true)))));
    thing = assetStorageService.merge(thing);
    thingId = thing.getId();
    // Some sample datapoints
    final ServerAsset finalThing = assetStorageService.find(thingId, true);
    ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
    AssetAttribute light1PowerConsumptionAttribute = thing.getAttribute("light1PowerConsumption").orElseThrow(() -> new RuntimeException("Invalid test data"));
    persistenceService.doTransaction(em -> {
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(0.11), now.minusDays(80).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(1.22), now.minusDays(40).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(2.33), now.minusDays(20).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(3.44), now.minusDays(10).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(4.55), now.minusDays(8).toEpochSecond() * 1000);
        light1PowerConsumptionAttribute.setValue(Values.create(5.66), now.minusDays(6).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(6.77), now.minusDays(3).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(7.88), now.minusDays(1).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(8.99), now.minusHours(10).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(9.11), now.minusHours(5).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(10.22), now.minusHours(2).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(11.33), now.minusHours(1).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(11.44), now.minusMinutes(30).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(12.00), now.minusMinutes(5).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(12.11), now.minusSeconds(5).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
        light1PowerConsumptionAttribute.setValue(Values.create(12.22), now.minusSeconds(1).toEpochSecond() * 1000);
        assetDatapointService.processAssetUpdate(em, finalThing, light1PowerConsumptionAttribute, AttributeEvent.Source.SENSOR);
    });
    // ################################ Demo assets for 'customerA' realm ###################################
    ServerAsset smartHome = new ServerAsset();
    smartHome.setRealmId(customerATenant.getId());
    smartHome.setName("Smart Home");
    smartHome.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
    smartHome.setType(BUILDING);
    smartHome.setAttributes(new AssetAttribute("geoStreet", STRING, Values.create("Wilhelminaplein 21C")).setMeta(new MetaItem(LABEL, Values.create("Street")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoStreet"))), new AssetAttribute("geoPostalCode", AttributeType.NUMBER, Values.create(5611)).setMeta(new MetaItem(LABEL, Values.create("Postal Code")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoPostalCode"))), new AssetAttribute("geoCity", STRING, Values.create("Eindhoven")).setMeta(new MetaItem(LABEL, Values.create("City")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCity"))), new AssetAttribute("geoCountry", STRING, Values.create("Netherlands")).setMeta(new MetaItem(LABEL, Values.create("Country")), new MetaItem(ABOUT, Values.create("http://project-haystack.org/tag/geoCountry"))));
    smartHome = assetStorageService.merge(smartHome);
    smartHomeId = smartHome.getId();
    // The "Apartment 1" is the demo apartment with complex scenes
    ServerAsset apartment1 = createDemoApartment(smartHome, "Apartment 1");
    apartment1 = assetStorageService.merge(apartment1);
    apartment1Id = apartment1.getId();
    ServerAsset apartment1ServiceAgent = new ServerAsset("Service Agent (Simulator)", AGENT, apartment1);
    apartment1ServiceAgent.setAttributes(initProtocolConfiguration(new AssetAttribute("apartmentSimulator"), SimulatorProtocol.PROTOCOL_NAME).addMeta(new MetaItem(SimulatorProtocol.CONFIG_MODE, Values.create(SimulatorProtocol.Mode.WRITE_THROUGH_IMMEDIATE.toString()))));
    apartment1ServiceAgent = assetStorageService.merge(apartment1ServiceAgent);
    apartment1ServiceAgentId = apartment1ServiceAgent.getId();
    /* ############################ ROOMS ############################## */
    ServerAsset apartment1Livingroom = createDemoApartmentRoom(apartment1, "Living Room");
    addDemoApartmentRoomMotionSensor(apartment1Livingroom, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    addDemoApartmentRoomCO2Sensor(apartment1Livingroom, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    addDemoApartmentRoomHumiditySensor(apartment1Livingroom, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    addDemoApartmentRoomThermometer(apartment1Livingroom, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    addDemoApartmentTemperatureControl(apartment1Livingroom, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);
    apartment1LivingroomId = apartment1Livingroom.getId();
    ServerAsset apartment1Kitchen = createDemoApartmentRoom(apartment1, "Kitchen");
    addDemoApartmentRoomMotionSensor(apartment1Kitchen, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    for (String switchName : new String[] { "A", "B", "C" }) {
        addDemoApartmentSmartSwitch(apartment1Kitchen, switchName, true, attributeIndex -> {
            switch(attributeIndex) {
                case 2:
                    return new MetaItem[] { new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) };
                case 3:
                    return new MetaItem[] { new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) };
                case 4:
                    return new MetaItem[] { new MetaItem(AssetMeta.AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) };
            }
            return null;
        });
    }
    apartment1Kitchen = assetStorageService.merge(apartment1Kitchen);
    apartment1KitchenId = apartment1Kitchen.getId();
    ServerAsset apartment1Hallway = createDemoApartmentRoom(apartment1, "Hallway");
    addDemoApartmentRoomMotionSensor(apartment1Hallway, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    apartment1Hallway = assetStorageService.merge(apartment1Hallway);
    apartment1HallwayId = apartment1Hallway.getId();
    addDemoApartmentVentilation(apartment1, true, () -> new MetaItem[] { new MetaItem(AGENT_LINK, new AttributeRef(apartment1ServiceAgentId, "apartmentSimulator").toArrayValue()), new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME)) });
    apartment1 = assetStorageService.merge(apartment1);
    if (importDemoScenes) {
        Scene[] scenes = new Scene[] { new Scene("homeScene", "Home scene", "HOME", "0 0 7 ? *", false, 21d), new Scene("awayScene", "Away scene", "AWAY", "0 30 8 ? *", true, 15d), new Scene("eveningScene", "Evening scene", "EVENING", "0 30 17 ? *", false, 22d), new Scene("nightScene", "Night scene", "NIGHT", "0 0 22 ? *", true, 19d) };
        ServerAsset demoApartmentSceneAgent = createDemoApartmentSceneAgent(apartment1, scenes, apartment1Livingroom, apartment1Kitchen, apartment1Hallway);
        demoApartmentSceneAgent = assetStorageService.merge(demoApartmentSceneAgent);
        linkDemoApartmentWithSceneAgent(apartment1, demoApartmentSceneAgent, scenes);
        apartment1 = assetStorageService.merge(apartment1);
    }
    ServerAsset apartment2 = new ServerAsset("Apartment 2", RESIDENCE, smartHome);
    apartment2.setLocation(smartHome.getLocation());
    apartment2.setAttributes(new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("All Lights Off Switch")), new MetaItem(DESCRIPTION, Values.create("When triggered, turns all lights in the apartment off")), new MetaItem(RULE_EVENT, Values.create(true)), new MetaItem(RULE_EVENT_EXPIRES, Values.create("3s"))));
    apartment2 = assetStorageService.merge(apartment2);
    apartment2Id = apartment2.getId();
    ServerAsset apartment2Livingroom = new ServerAsset("Living Room", ROOM, apartment2);
    apartment2Livingroom.setLocation(apartment2.getLocation());
    apartment2Livingroom.setAttributes(new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")), new MetaItem(DESCRIPTION, Values.create("PIR sensor that sends 'true' when motion is sensed")), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(RULE_EVENT, Values.create(true))), new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Presence Detected")), new MetaItem(DESCRIPTION, Values.create("Someone is currently present in the room")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("firstPresenceDetected", AttributeType.TIMESTAMP_MILLIS).setMeta(new MetaItem(LABEL, Values.create("First Presence Timestamp")), new MetaItem(DESCRIPTION, Values.create("Timestamp of the first detected presence")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("lastPresenceDetected", AttributeType.TIMESTAMP_MILLIS).setMeta(new MetaItem(LABEL, Values.create("Last Presence Timestamp")), new MetaItem(DESCRIPTION, Values.create("Timestamp of last detected presence")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("co2Level", AttributeType.CO2_PPM, Values.create(350)).setMeta(new MetaItem(LABEL, Values.create("CO2 Level")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("Light Switch")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(ACCESS_RESTRICTED_READ, Values.create(true))));
    apartment2Livingroom = assetStorageService.merge(apartment2Livingroom);
    apartment2LivingroomId = apartment2Livingroom.getId();
    ServerAsset apartment2Bathroom = new ServerAsset("Bathroom", ROOM, apartment2);
    apartment2Bathroom.setLocation(apartment2.getLocation());
    apartment2Bathroom.setAttributes(new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Motion Sensor")), new MetaItem(DESCRIPTION, Values.create("PIR sensor that sends 'true' when motion is sensed")), new MetaItem(RULE_STATE, Values.create(true)), new MetaItem(RULE_EVENT, Values.create(true))), new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Values.create(false)).setMeta(new MetaItem(LABEL, Values.create("Presence Detected")), new MetaItem(DESCRIPTION, Values.create("Someone is currently present in the room")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("firstPresenceDetected", AttributeType.TIMESTAMP_MILLIS).setMeta(new MetaItem(LABEL, Values.create("First Presence Timestamp")), new MetaItem(DESCRIPTION, Values.create("Timestamp of the first detected presence")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("lastPresenceDetected", AttributeType.TIMESTAMP_MILLIS).setMeta(new MetaItem(LABEL, Values.create("Last Presence Timestamp")), new MetaItem(DESCRIPTION, Values.create("Timestamp of last detected presence")), new MetaItem(RULE_STATE, Values.create(true))), new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Values.create(true)).setMeta(new MetaItem(LABEL, Values.create("Light Switch")), new MetaItem(RULE_STATE, Values.create(true))));
    apartment2Bathroom = assetStorageService.merge(apartment2Bathroom);
    apartment2BathroomId = apartment2Bathroom.getId();
    ServerAsset apartment3 = new ServerAsset("Apartment 3", RESIDENCE, smartHome);
    apartment3.setLocation(smartHome.getLocation());
    apartment3 = assetStorageService.merge(apartment3);
    apartment3Id = apartment3.getId();
    ServerAsset apartment3Livingroom = new ServerAsset("Living Room", ROOM, apartment3);
    apartment3Livingroom.setLocation(apartment3.getLocation());
    apartment3Livingroom.addAttributes(new AssetAttribute("lightSwitch", AttributeType.BOOLEAN));
    apartment3Livingroom = assetStorageService.merge(apartment3Livingroom);
    apartment3LivingroomId = apartment3Livingroom.getId();
    // ################################ Link demo users and assets ###################################
    assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.customerATenant.getId(), keycloakDemoSetup.testuser3Id, apartment1Id));
    assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.customerATenant.getId(), keycloakDemoSetup.testuser3Id, apartment1LivingroomId));
    assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.customerATenant.getId(), keycloakDemoSetup.testuser3Id, apartment1KitchenId));
    assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.customerATenant.getId(), keycloakDemoSetup.testuser3Id, apartment1HallwayId));
    assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.customerATenant.getId(), keycloakDemoSetup.testuser3Id, apartment2Id));
}
Also used : AssetMeta(org.openremote.model.asset.AssetMeta) UserAsset(org.openremote.model.asset.UserAsset) ServerAsset(org.openremote.manager.asset.ServerAsset) Tenant(org.openremote.model.security.Tenant) Coordinate(com.vividsolutions.jts.geom.Coordinate) ZonedDateTime(java.time.ZonedDateTime) AssetAttribute(org.openremote.model.asset.AssetAttribute)

Example 24 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project ddf by codice.

the class OpenSearchFilterVisitor method visit.

/**
     * Contains filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Contains filter, Object data) {
    LOGGER.trace("ENTERING: Contains filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Contains filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Contains filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Example 25 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project ddf by codice.

the class OpenSearchFilterVisitor method visit.

/**
     * Intersects filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.trace("ENTERING: Intersects filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        StringBuffer geometryWkt = new StringBuffer();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Coordinate[] coords = polygon.getJTSGeometry().getCoordinates();
            geometryWkt.append("POLYGON((");
            for (int i = 0; i < coords.length; i++) {
                geometryWkt.append(coords[i].x);
                geometryWkt.append(" ");
                geometryWkt.append(coords[i].y);
                if (i != (coords.length - 1)) {
                    geometryWkt.append(",");
                }
            }
            geometryWkt.append("))");
            this.spatialSearch = new SpatialFilter(geometryWkt.toString());
            LOGGER.debug("geometryWkt = [{}]", geometryWkt.toString());
            filters.add(filter);
        } else {
            LOGGER.debug("Only POLYGON geometry WKT for Intersects filter is supported");
        }
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Intersects filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11