Loading geoJSON to Cesium does not work but I get no errors - gis

I try to pass data from PostGIS to Cesium, I believe the simpler way is to use GeoJSON.
To test it I do a query to my PostGIS to get some geoJSON data
SELECT ST_AsGeoJSON(mygeom)
FROM mytable where id = 370;
then I copy the result to a cesium sandcastle to see how it works
var viewer = new Cesium.Viewer('cesiumContainer');
const greenPolygon = viewer.entities.add({
name: "Green extruded polygon",
polygon: {
hierarchy : Cesium.GeoJsonDataSource.load({"type":"MultiPolygon","coordinates":[[[[386788.842267334,4204512.29371444],[386804.47751787,4204512.29371444],[386804.47751787,4204510.66293459],[386788.854170836,4204510.66293459],[386788.842267334,4204512.29371444]]]]}),
extrudedHeight: 100000.0,
material: Cesium.Color.YELLOW.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK,
closeTop: true,
closeBottom: true
},
});
viewer.zoomTo(viewer.entities);
I get no errors in the cesium sandcastle console, but I also see no polygon on the map. The geometry in my PostGIS table is geometry(MultiPolygon,2100), I dont know if this is the issue.
Please advice
Thanks

CesiumJS will not understand your coordinates(ex 386788.842267334,4204512.29371444) defined in your custom spatial reference system.
You must specify coordinates using geographic latitude, and longitude.

Related

Forge Viewer loading multiple Revit models with shared coordinates

When loading Revit models which are aligned by shared coordinates, the models does not align in Forge Viewer with globallOffset settings.
The loadModel with placementTransform option seems to be viable, but the shared coordinates data is not made available until after the model is loaded, via viewer.model.getDocumentNode().getAecModelData().refPointTransformation
earliest I have the model data is inside the onLoadModelSuccess which is too late to feed into the load options, and will require to transform the geometries.
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: offset,
placementTranform: ???,
isAEC: true
};
viewer.loadModel(svfUrl, modelOptions, onLoadModelSuccess, onLoadModelError);
How would it be possible to align the models otherwise? Or maybe to load the model without rendering the geometry first to get the data then feed the transform matrix into another loadModel call?
Use the following two options together to apply Revit shared coords:
globalOffset - tells LMV not to auto centre model
applyRefPoint - tells LMV how to apply any svf positioning meta-data for Revit files
So try the below in your load options:
var modelOptions = {
sharedPropertyDbPath: doc.getPropertyDbPath(),
globalOffset: offset,
applyRefPoint: true,
isAEC: true
};
And see this live sample here for usage reference on the placementTranform option.

Access to polygon matrix from json files

I load polygons from json file using loadGeoJson. In json file I have properties name and id. All Polygons loads correctly on the map.
How can I get matrix of all polygons? I need to check that my point containsLocation of one from this polygons. TIA 4 answer
I use :
var woj =[];
map.data.addListener('addfeature', function(event) {
var adm=event.feature.getProperty('id');
woj.push(adm);
});
That solves my problem.

Database instead of kml file

I wonder, is it possible to connect a db to google maps api to render polygons, points etc?
If a store all kml coordinates connected to polygons, will it be possible to render it fra database or do i need to create a kml file to visualize it?
Is there any example?
Thanks!
A KML file is not required to visualize points, polygons, etc using Google Maps API. However, the KML layer is a useful way to represent complex geospatial features.
A backend database with HTTP access could return a list of map coordinates that your client code can render into appropriate shapes using Google Maps API.
The Google Maps API provides examples to create various shapes.
Example to create simple point marker:
https://developers.google.com/maps/documentation/javascript/examples/marker-simple
Example to create simple polygon:
https://developers.google.com/maps/documentation/javascript/examples/polygon-simple
The client code will need to query the data from the database such as from a servlet with access to the database. Database will most likely be running on a different port or from a different server so javascript won't be able to access it directly.
Your server-side component could query a database and return formatted KML or it could return a JSON result that your client code would render. Depends on whether you want to write more backend server code or JavaScript code on the client.
hmmm... I am using another solution now (data from DB to show on Google earth which is default application for KML file) and hope this help :
( may refer to https://sites.google.com/site/canadadennischen888/home/kml/auto-refresh-3d-tracking )(plus, in my other page, there is sample java code)
Details as :
prepare a RestFul service to generate KML file from DB (KML sample as inside above link)
My other jsp code will generate a KMZ file which has a link to my Restful service. KMZ file has onInterval ( as in the bottom)
Jsp web page allow user to download KMZ file.
When Google Earth open KMZ file, Google Earth will auto refresh to get new data from that Restful service
Everytime refreshing, server will send the latest update KML data with new data to GE.
KMZ sample:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"
xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<NetworkLink>
<name>Dennis_Chen_Canada#Hotmail.com</name>
<open>1</open>
<Link>
<href>http://localhost:9080/google-earth-project/rest/kml/10001/20002</href>
<refreshMode>onInterval</refreshMode>
</Link>
</NetworkLink>
</kml>
result as :
Thanks for you're answer. I don't know if i get somewhat wiser of this, but at least i know that it is possible.
I have used Shape2Sql to save the coordinates in the database.
But as i understand, i need someway to convert this to geojson before it can render in Google maps? if i understand correct?
As i understand to render geojson is mostly the same as to render kml when it comes to files. But i don't know how to Connect to a database.
I make a list from database:
var adresses = _unitOfWork.GeoAddressRepository.Get(q => q.GeoRouteNorpost.Code == "3007106", includeProperties: "GeoRouteNorpost").ToList();
var points = new List<LatLong>();
foreach (var address in adresses)
{
points.Add(new LatLng() { Lat = "59.948261", Lng = "10.750699" });
points.Add(new LatLng() { Lat = "59.943128", Lng = "10.755814" });
points.Add(new LatLng() { Lat = "59.941245", Lng = "10.746084" });
points.Add(new LatLng() { Lat = "59.943527", Lng = "10.742786" });
points.Add(new LatLng() { Lat = "59.946824", Lng = "10.744435" });
points.Add(new LatLng() { Lat = "59.946813", Lng = "10.744446" });
points.Add(new LatLng() { Lat = "59.947107", Lng = "10.748241" });
points.Add(new LatLng() { Lat = "59.947827", Lng = "10.749525" });
points.Add(new LatLng() { Lat = "59.948248", Lng = "10.750699" });
}
This example show a polygon on a map. But i'm not sure how to get this coordinates out of the database and how to solve it when it is serveral polygons.
As i have written, i have saved the coordinates in the db With shape2Sql. So now i have a Field for geometry. If i look at the spatial result in sql server this looks correct. But how can i display this in Google maps?
I am grateful for all help:)

Map route not working in Titanium Appcelerator

i'm having some trouble with Maps Route y Maps V2 on Android. So the problem is when i put a route, like this:
var cord1= {
latitude:29.078685,
longitude:-110.971205,
};
var cord2= {
latitude:29.081496,
longitude:-110.959232,
};
var route1 = [cord1, cord2];
var route = MapModule.createRoute({
points : route1,
color : "red",
width : 5.0
});
$.mapview.addRoute(route);
And yeah, now i have a map route in my map, but the route is straight, totally straight
Picture of the map route!
The route is not using the streets, is just a straight line, not sable at all, can you help me?
My specifications:
Mac OS Maverick
Module: Ti.map (API V2)
Titanium SDK 3.2.2.GA
Titanium Studio, build: 3.2.1.201402041146
(c) Copyright 2012-2013 by Appcelerator, Inc. All rights reserved.
Build: jenkins-titanium-rcp-master-95 (origin/master)
Date: 04 February 2014, 11:47:38
You need more coordinates not just a start an end but many points in between. Since this is just one route, your coordinates must be stored in an array consecutively. That array should be used for the points property when creating a route. Here's an example from appecelerator's documents and the route examples are at the very bottom of the page: http://docs.appcelerator.com/titanium/3.0/#!/guide/Native_Maps_and_Annotations
Like this:
var _points = []; // The array used to contain the points in a route
//Your coordinates
var cord1= {
latitude:29.078685,
longitude:-110.971205,
};
_points.push(cord1);
var cord2= {
latitude:29.081496,
longitude:-110.959232,
};
_points.push(cord2);
// Create your route
var route = MapModule.createRoute({
points : _points,
color : "#f00",
width : 5.0
});
// Add route to map!
$.mapview.addRoute(route);
In titanium if you provide only two points in route then it will draw a straight line between those points. If you want to make more accurate route, then try to provide more [cords] points.
try KitchenSink
I too was stuck with the same problem But find a solution to this . The solution is using a Google Places API that provides you points between your starting and destination points as a result a more accurate route is drawn on the map!!!!Hope this works for you .

save google map polygon to postgreSQL database

I develop a web-based application where a user will create a polygon on a map and the database
will return points of interest.
The problem is that the postgreSQL saves the polygon in a different way than google map polygon.
So how I can save the user polygon to postgis?
I already use google maps v3 api and geojson
Some code would be useful. In the absence of that here's a best guess generic answer: In general terms you will need to work out how to map (convert) each format to the other. Then you can convert to the format suitable for the database before you save and convert from database format to google maps format when you retrieve. I imagine each polygon is a set of latitude/longitude pairs in both formats so it shouldn't be too difficult.
Alternatively, since you're using JSON, you could just save the JSON to a text field in the database (or to a JSON field in the upcoming 9.2 release of PostgreSQL):
http://www.postgresql.org/docs/9.2/static/datatype-json.html
However if you would like to perform geographical queries in the database that would obviously limit your options.
In my js file i create a shape which is polygon
shape = new google.maps.Polygon({
Editable:true,
strokeColor: 'FF0000',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: 'FF0000',
fillOpacity: 0.4
});
Then I create the function addPoint
function addPoint(e) {
shape.setMap(map);
vertices= shape.getPath();
vertices.push(e.latLng);
polygon.push(e.latLng);
}
I pass the addPoint function to map object
map = new google.maps.Map(document.getElementById("map"), mapOptions);
google.maps.event.addListener(map,'click',addPoint);
In my html I have the button with id=polygon. I convert the coordinates in postgres format (long,lat)
$("#polygon").click(function(e){
a=JSON.stringify(polygon);
var c=JSON.parse(a);
console.info(c);
vertices.forEach(function(xy, i) {
x.push(xy.lng()+" "+xy.lat());
});
shape.setMap(map);
The variable which contains the polygon is the array which I called it x
the I have an ajax call to pass polygon array x to my model
$.ajax({
url: 'myurl',
type: 'post',
data: {'polygon':x},
datatype: 'json',
success: function(data) {
console.info(data)
}
});
In my model (Codeigniter) I convert the polygon (lat,long) to postgres polygon (long,lat)
public function getPolygon($polygon){
header('Content-type: application/json');
$upolygon="";
$length=count($polygon);
for ($i=0;$i<$length;$i++){
$upolygon.=$polygon[$i].' ,';
}
$upolygon.=$polygon[0];
$query = "some query with the formated polygon";
foreach ($query->result() as $row)
{
$data[]= array("some data");
}
echo json_encode($data);
}