I have an entity called Shop which has a DBGeorgpraphy column called Position
A sample shop in the database has a Position value of POINT (145.034242 -37.825519)
I am trying to retrieve all shops that fall within a polygon.
var polygon = DbGeography.PolygonFromText(#"POLYGON((145.2898592378906 -37.66376896413059,
145.2898592378906 -37.93504877166811,
144.7075838472656 -37.93504877166811,
144.7075838472656 -37.66376896413059,
145.2898592378906 -37.66376896413059))",
4326);
var shops = db.Shops.Where(p => p.Position.Intersects(polygon));
I would expect the sample shop to be included in the results but it doesn't. Can anyone enlighten me?
The answer is to construct the polygon in the opposite direction, i.e. anti-clockwise.
var polygon = DbGeography.PolygonFromText(#"POLYGON((145.2898592378906 -37.66376896413059,
144.7075838472656 -37.66376896413059,
144.7075838472656 -37.93504877166811,
145.2898592378906 -37.93504877166811,
145.2898592378906 -37.66376896413059))",
4326);
Related
I have two geometries with the same coordinate system (Wgs84), but their data units are different, one is degree and the other is meter.
I need to perform some operations on them, like:
var g1 = GeometryEngine.Difference(geometry1, geometry2);
But I got an error:
System.ArgumentException:'Invalid argument: geometry1 and geometry2 must have equivalent spatial references.'
So I want to convert the data in degrees to the data in meters, I don’t know how to do it.
The data in meters comes from the shp file. This shp file is loaded into SceneView.
The data in degrees comes from the PreviewMouseLeftButtonDown event of SceneView:
// Get the mouse position.
Point cursorSceenPoint = mouseEventArgs.GetPosition(MySceneView);
// Get the corresponding MapPoint.
MapPoint onMapLocation = MySceneView.ScreenToBaseSurface(cursorSceenPoint);
Then I thought about whether the unit can be modified by setting SceneView.SpatialReference.Unit, but it is read-only.
A .NET solution is the best, and other languages are also acceptable.
Most geometry engine operations requires all geometries to be in the same spatial reference. As the error points to, that is not the case. Before performing any geometry engine operation, you could use the following code to bring geometry2 over to match the spatial reference of geometry1 (or vise-versa):
if (!geometry1.SpatialReference.IsEqual(geometry2.SpatialReference))
geometry2 = GeometryEngine.Project(geometry2, geometry1.SpatialReference);
The SceneView always returns coordinates in wgs84 lat/long.
var point1 = ...;
var point2= GeometryEngine.Project(point1, YourNewSpatialReference) as MapPoint;
public static Geometry? Project(Geometry geometry, SpatialReference outputSpatialReference);
public static Geometry? Project(Geometry geometry, SpatialReference outputSpatialReference, DatumTransformation? datumTransformation);
I am trying to make a Traffic Simulator for my bachelor thesis.
I created a map with OpenStreetMap osm and now I am trying to put some cars on roads.
I created a graph for the roads. The graph is like this:
A->B,C,D
C->A,B,E
B->A,C
D->A
E->C
and I generate random the cars on random points A,B,C,D,E,F. After this I use function getShortestPath(start,end) to get the shortest path for every car and I put the cars to move:
foreach(Car c in allCars){
Move(c,path)
}
But, I have a problem, I don't know how to keep the correct lane of road for every car, all my cars are on the same lane of road.
I am thinking about the direction between two points and the car will be at the right side of the direction.
But I have no idea how to do this....
Thank you!
Here is my answer to update your movement and car code, taking into account our conversation in the comments.
Add a variable to your car class:
Class Car {
// your other variables
Vector3 progressPosition; // This will only be set to the from nodes position whenever you get a new path.
}
Your update code will be like this:
void UpdateCarMethod()
{
car.car.progressPosition = Vector3.MoveTowards(car.car.progressPosition, car.path[car.index].point + lane, Time.deltaTime * speed);
car.car.transform.position = car.car.progressPosition + car.car.transform.right;
}
I have a Sketchup 3d model that is geo-located. I can get the geo-location of the model as follows :-
latitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Latitude"]
longitude = Sketchup.active_model.attribute_dictionaries["GeoReference"]["Longitude"]
Now i want to render this model on a 3D globe. So i need the location bounds of the 3d model.
Basically i need bounding box of the model on 2d map.
Right now i am extracting the same from the corners of a model(8 corner).
// This will return left-front-bottom corner.
lowerCorner = Sketchup.active_model.bounds.corner(0)
// This will return right-back-top corner.
upperCorner = Skectup.active_model.bounds.corner(6)
But it returns simple geometrical points in meters, inches depending upon the model.
For example i uploaded this model in sketchup. Following are the values of geo-location, lowerCorner and upperCorner respectively that i'm getting by using the above code for the above model.
geoLocation : 25.141407985864, 55.18563969191 //lat,long
lowerCorner : (-9483.01089", -6412.376053", -162.609524") // In inches
upperCorner : (-9483.01089", 6479.387909", 12882.651999") // In inches
So my first question is what i'm doing is correct or not ?
Second question is If yes for the first how can i get the values of lowerCorner and upperCorner in lat long format.
But it returns simple geometrical points in meters, inches depending upon the model.
Geom::BoundingBox.corner returns a Geom::Point3d. The x, y and z members of that is a Length. That is always returning the internal value of SketchUp which is inches.
However, when you use Length.to_s it will use the current model's unit settings and format the values into that. When you call Geom::Point3d.to_s it will use Length.to_s. On the other hand, if you call Geom::Point3d.inspect it will print the internal units (inches) without formatting.
Instead of tapping into the attributes of the model directly like that I recommend you use the API methods of geo-location: Sketchup::Model.georeferenced?
By the sound of it you might find Sketchup::Model.point_to_latlong useful.
Example - I geolocated a SketchUp model to the town square of Trondheim, Norway (Geolocation: 63°25′47″N 10°23′36″E):
model = Sketchup.active_model
bounds = model.bounds
# Get the base of the boundingbox. No need to get the top - as the
# result doesn't contain altiture information.
(0..3).each { |i|
pt = bounds.corner(i)
latlong = model.point_to_latlong(pt)
latitude = latlong.x.to_f
longitude = latlong.y.to_f
puts "#{pt.inspect} => #{longitude}, #{latitude}"
}
I'm trying to implement a function that returns all entries of my table that contains polygons (that describe areas) within a specific radius (distance). I found the function SDO_GEOM.SDO_WITHIN_DISTANCE and read this post.
Since this is a theoretical approach and I have no real data - and I'm not a native speaker, I'm not sure at all if this function is able to do that.
First of all, you need to use the SDO_WITHIN_DISTANCE operator, not the SDO_GEOM.WITHIN_DISTANCE function. The first will perform a search using the spatial index on the polygons table. The second will not (and so will be very slow).
Then SDO_WITHIN_DISTANCE may or may not be what you need, depending on the way you define "within a radius". If by that you mean that the closest border of a polygon must be within the radius, then SDO_WITHIN_DISTANCE is what you need.
Let's assume you have a table AREAS (ID, GEOMETRY) and a table LOCATIONS (ID, GEOMETRY) and you want to find all areas within 10 km of point 42:
select a.id
from areas a, locations l
where l.id=42
and sdo_within_distance (a.geometry, l.geometry, 'distance=10 unit=km') = 'TRUE';
On the other hand, if you want to find polygons that are completely contained within the radius, then you need to construct a buffer of 10 km and use that as a search area to find the matching polygons:
select a.id
from areas a, locations l
where l.id=42
and sdo_inside (
a.geometry,
sdo_geom.sdo_buffer (
l.geometry,
10,
0.05,
'unit=km'
)
) = 'TRUE';
It's possible to use SDO_GEOM.SDO_WITHIN_DISTANCE in a WHERE clause to do what you want - i.e. restrict the rows based on their distance from an origin shape.
I have some countries polygon. I want to draw them on top of my sphere with three js, but when I'm trying to draw these polygons, fps drop down, at 3fps....
Someone told me to create juste ONE geometry and include all the polygons into it, did you have an example?
What I'm doing:
foreach countrie in countries
geometry = new THREE.shapeGeometry();
geometry.push(vectorArray);
var mesh = new Mesh(geometry);
globe.Add(mesh);
With over 250 countries, Three js just creates over 38k buffer. Strange behaviour, without any control, we shouldn't be able to create such buffers... so where am I wrong? I need help.
The three.js class THREE.GeometryUtils has a number of helpful methods for situations like these...
In particular, there is a merge method that will combine two Geometry objects into one. Assume that you have three geometry objects, country1, country2, country3. Then you could do something like:
temp = THREE.GeometryUtils.merge( country1, country2 );
allCountries = THREE.GeometryUtils.merge( temp, country3 );
Hope this helps!