Skip to content

Commit

Permalink
[CSAPI] Updated demo data
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrobin committed Sep 29, 2024
1 parent 720c11e commit 0f8fa99
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import org.sensorhub.api.common.BigId;
import org.sensorhub.api.data.IDataStreamInfo;
import org.sensorhub.api.data.IObsData;
import org.sensorhub.api.semantic.IDerivedProperty;
import org.sensorhub.impl.service.consys.client.ConSysApiClient;
import org.sensorhub.impl.service.consys.resource.ResourceFormat;
import org.vast.ogc.gml.GeoJsonBindings;
import org.vast.ogc.gml.IFeature;
import org.vast.sensorML.SMLJsonBindings;
Expand All @@ -48,9 +50,34 @@ public class Api
{
static String API_ROOT = "http://localhost:8181/sensorhub/api/";
static String CREDENTIALS = "admin:test";
// static String API_ROOT = "https://api.georobotix.io/ogc/demo1/api/";
// static String CREDENTIALS = "admin:admin@demo";
static Gson gson = new GsonBuilder().setPrettyPrinting().create();


static String addOrUpdateProperty(IDerivedProperty prop, boolean replace) throws IOException
{
var user = CREDENTIALS.split(":")[0];
var pwd = CREDENTIALS.split(":")[1];
var client = ConSysApiClient.newBuilder(API_ROOT)
.simpleAuth(user, pwd.toCharArray())
.build();

/*var id = client.getPropertyByUri(prop.getURI(), ResourceFormat.JSON).get();
if (id == null)
throw new IllegalArgumentException("Parent system not found: " + sysUid);*/

try
{
return client.addProperty(prop).get();
}
catch (InterruptedException | ExecutionException e)
{
throw new IOException(e);
}
}


static String addOrUpdateProcedure(AbstractProcess obj, boolean replace) throws IOException
{
return addOrUpdateSmlResource("procedures", obj, replace);
Expand Down Expand Up @@ -95,6 +122,7 @@ static String addOrUpdateSmlResource(String resourceType, DescribedObject obj, b
var strWriter = new StringWriter();
var bindings = new SMLJsonBindings();
bindings.writeDescribedObject(new JsonWriter(strWriter), obj);
System.out.println(strWriter.toString());

if (id == null || !replace)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.sensorhub.api.data.DataStreamInfo;
import org.sensorhub.api.data.IDataStreamInfo;
import org.sensorhub.api.system.SystemId;
import org.vast.ogc.geopose.Pose;
import org.vast.ogc.geopose.PoseImpl.PoseBuilder;
import org.vast.ogc.gml.IFeature;
import org.vast.sensorML.SMLHelper;
import org.vast.sensorML.SMLMetadataBuilders.CIResponsiblePartyBuilder;
Expand All @@ -43,6 +45,7 @@
import net.opengis.gml.v32.Point;
import net.opengis.gml.v32.impl.GMLFactory;
import net.opengis.sensorml.v20.AbstractProcess;
import net.opengis.sensorml.v20.PhysicalSystem;
import net.opengis.swe.v20.BinaryBlock;
import net.opengis.swe.v20.BinaryComponent;
import net.opengis.swe.v20.BinaryEncoding;
Expand Down Expand Up @@ -257,7 +260,7 @@ static AbstractProcess createSD22204Datasheet()
}


static AbstractProcess createCameraInstance(String id, Point location, double heading, Instant startTime)
static AbstractProcess createCameraInstance(String id, Pose pose, double heading, Instant startTime)
{
return sml.createPhysicalSystem()
.definition(SWEConstants.DEF_SENSOR)
Expand All @@ -267,7 +270,7 @@ static AbstractProcess createCameraInstance(String id, Point location, double he
.addIdentifier(sml.identifiers.shortName("Dahua PTZ Cam " + id))
.addContact(getOperatorContactInfo())
.validFrom(startTime.atOffset(ZoneOffset.UTC))
.location(location)
.position(pose)
.build();
}

Expand All @@ -277,20 +280,28 @@ static Collection<AbstractProcess> getCameraInstances()
var list = new ArrayList<AbstractProcess>(100);

var fac = new GMLFactory();
var locations = new Point[] {
/*var locations = new Point[] {
fac.newPoint(103.868811, 1.327909),
fac.newPoint(103.879014, 1.331288),
fac.newPoint(103.869337, 1.332328),
fac.newPoint(103.863479, 1.322020),
fac.newPoint(103.862309, 1.330440),
fac.newPoint(103.855743, 1.329089)
};*/
var positions = new Pose[] {
new PoseBuilder().latLonPos(103.868811, 1.327909).eulerAngles(123, -10, 0).build(),
new PoseBuilder().latLonPos(103.879014, 1.331288).eulerAngles(80, -10, 0).build(),
new PoseBuilder().latLonPos(103.869337, 1.332328).eulerAngles(190, -10, 0).build(),
new PoseBuilder().latLonPos(103.863479, 1.322020).eulerAngles(128, -10, 0).build(),
new PoseBuilder().latLonPos(103.862309, 1.330440).eulerAngles(115, -10, 0).build(),
new PoseBuilder().latLonPos(103.855743, 1.329089).eulerAngles(95, -10, 0).build()
};

for (int i = 0; i < locations.length; i++)
for (int i = 0; i < positions.length; i++)
{
list.add(createCameraInstance(
String.format("SG%05d", (i+10)),
locations[i],
positions[i],
0.0,
Instant.parse("2020-04-28T08:00:00Z").plus((i+1)*(i-1), ChronoUnit.DAYS)
));
Expand Down Expand Up @@ -329,6 +340,8 @@ static IFeature createTrafficCamSf(AbstractProcess sys)
{
var sysUid = sys.getUniqueIdentifier();
var camId = sysUid.substring(sysUid.lastIndexOf(':')+1);
var pose = (Pose)((PhysicalSystem)sys).getPositionList().get(0);
var heading = pose.getOrientation()[0];

var sf = new ViewingSector();
sf.setUniqueIdentifier(sysUid + ":sf");
Expand All @@ -338,8 +351,8 @@ static IFeature createTrafficCamSf(AbstractProcess sys)
sf.setRadius(150.0);
sf.setMinElevation(-90.0);
sf.setMaxElevation(25.0);
sf.setMinAzimuth(23.0);
sf.setMaxAzimuth(223.0);
sf.setMinAzimuth(heading-100);
sf.setMaxAzimuth(heading+100);

return sf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static void main(String[] args) throws IOException
{
// PhilipsHue.addResources();
// Davis.addResources();
// Dahua.addResources();
MavicPro.addResources();
Dahua.addResources();
// MavicPro.addResources();
// Saildrone.addResources();
// SpotSat.addResources();
// Pleiades.addResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collection;
import org.isotc211.v2005.gmd.CIOnlineResource;
import org.isotc211.v2005.gmd.CIResponsibleParty;
import org.sensorhub.api.command.CommandStreamInfo;
import org.sensorhub.api.command.ICommandStreamInfo;
import org.sensorhub.api.common.BigId;
import org.sensorhub.api.data.DataStreamInfo;
import org.sensorhub.api.data.IDataStreamInfo;
import org.sensorhub.api.semantic.IDerivedProperty;
import org.sensorhub.api.system.SystemId;
import org.vast.ogc.geopose.Pose;
import org.sensorhub.impl.semantic.DerivedProperty;
import org.vast.ogc.gml.IFeature;
import org.vast.ogc.om.SamplingPoint;
import org.vast.sensorML.SMLHelper;
Expand All @@ -34,12 +37,10 @@
import org.vast.sensorML.helper.CommonClassifiers;
import org.vast.sensorML.helper.CommonIdentifiers;
import org.vast.sensorML.sampling.ViewingFrustum;
import org.vast.sensorML.sampling.ViewingSector;
import org.vast.swe.SWEConstants;
import org.vast.swe.SWEHelper;
import org.vast.swe.helper.GeoPosHelper;
import org.vast.swe.helper.RasterHelper;
import net.opengis.gml.v32.Point;
import net.opengis.sensorml.v20.AbstractProcess;
import net.opengis.sensorml.v20.CapabilityList;
import net.opengis.swe.v20.BinaryBlock;
Expand All @@ -64,6 +65,10 @@ public class MavicPro

static void addResources() throws IOException
{
// add custom properties
//for (var prop: createCustomProperties())
// Api.addOrUpdateProperty(prop, true);

// add MavicPro datasheet
Api.addOrUpdateProcedure(createPlatformDatasheet(), true);
//Api.addOrUpdateProcedure(createCameraDatasheet(), true);
Expand Down Expand Up @@ -98,6 +103,21 @@ static void addResources() throws IOException
}


static Collection<IDerivedProperty> createCustomProperties()
{
var props = new ArrayList<IDerivedProperty>();

props.add(new DerivedProperty.Builder()
.uri("#Radio_Transmitter_Range")
.name("Radio Range")
.baseProperty(SWEHelper.getQudtUri("Distance"))
.objectType(SWEHelper.getDBpediaUri("Transmitter"))
.build());

return props;
}


static AbstractProcess createPlatformDatasheet()
{
return sml.createPhysicalSystem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.vast.sensorML.SMLHelper;
import org.vast.sensorML.SMLMetadataBuilders.CIResponsiblePartyBuilder;
import org.vast.sensorML.helper.CommonIdentifiers;
import org.vast.sensorML.sampling.SamplingSphere;
import org.vast.sensorML.sampling.ViewingSector;
import org.vast.swe.SWEConstants;
import org.vast.swe.SWEHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import org.vast.swe.SWEConstants;
import org.vast.swe.SWEHelper;
import org.vast.swe.helper.GeoPosHelper;
import org.vast.util.TimeExtent;
import net.opengis.gml.v32.impl.GMLFactory;
import net.opengis.sensorml.v20.AbstractProcess;
import net.opengis.sensorml.v20.Deployment;


public class Saildrone
Expand Down Expand Up @@ -119,6 +121,10 @@ static void addResources() throws IOException
.getJson();

//Api.addOrUpdateObs(navDsId, cgSfId, Instant.parse("2023-09-25T00:00:00Z"), result, true);

// add deployment
var deploy1 = createDeployment("2025", TimeExtent.parse("2017-07-17T00:00:00Z/2017-09-29T00:00:00Z"));
Api.addOrUpdateDeployment(deploy1, true);
}
}

Expand Down Expand Up @@ -213,7 +219,7 @@ static AbstractProcess createPlatformDatasheet()
.origin("Center of flotation of the USV")
.addAxis("X", "Along the longitudinal axis of the symmetry of the hull, pointing forward")
.addAxis("Y", "Orthogonal to both X and Z, forming a right handed frame")
.addAxis("Z", "Along the axis of rotation of the sail, pointing up")
.addAxis("Z", "Along the axis of rotation of the sail, pointing down")
)

.build();
Expand Down Expand Up @@ -457,5 +463,39 @@ static IDataStreamInfo createCtdDataStream(AbstractProcess platform, AbstractPro
)
.build();
}


static Deployment createDeployment(String num, TimeExtent validTime)
{
var fac = new GMLFactory();
var geom = fac.newPolygon();

//geom.getExterior().setPosList(null);

return sml.createDeployment()
.uniqueID("urn:x-osh:saildrone:mission:" + num)
.name("Saildrone - 2017 Arctic Mission")
.description("In July 2017, three saildrones were launched from Dutch Harbor, Alaska, in partnership with NOAA Research...")
.addContact(getOperatorContactInfo().role(CommonIdentifiers.OPERATOR_DEF))
.validTimePeriod(
validTime.begin().atOffset(ZoneOffset.UTC),
validTime.end().atOffset(ZoneOffset.UTC))
.location(null)
.build();
}


static CIResponsiblePartyBuilder getOperatorContactInfo()
{
return sml.createContact()
.role(SWEHelper.getPropertyUri("Operator"))
.organisationName("NOAA Pacific Marine Environmental Laboratory")
.website("https://pmel.noaa.gov")
.deliveryPoint("7600 Sand Point Way NE")
.city("Seattle")
.postalCode("98115")
.administrativeArea("WA")
.country("USA");
}

}

0 comments on commit 0f8fa99

Please sign in to comment.