Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016
Accepted Solution

Convert Geometry to x,y coordinates - URGENT

[ Edited ]

I need to know how to access the coordinate information in a geometry object the user draws.  The use will draw a point and I need the x and y coordinates

 

function createAnalysis(geometry) {
var queryName = "Query with drawing16";
$GP.queries.add({
featureClassId: "Access Connection - City|Plants",
url: "http://mycomp/MapService.svc",
definitionName: "MapPublisher",
queryName: queryName,
applicationId: "myApp",
addToLegend: true,
filters: [{
type: "spatial",
operator: 0,
complement: false,
operands: [geometry]

}]
},
function (result) {
$GP.queries.find({
analysisId: result.analysisId,
}, function (result2) {
result2.analysis.getData(function (data) {
console.log(data);
});
});
}
);
}

$GP.map.draw({
"type": "Point" //user will be promped to draw geometry (polygon) on map
}, function (r) {

createAnalysis(r.feature.get_geoJSON().geometry);
});

 

This works - user inputs a point and all "Plant" features that intersect the point are selected.

What i really want is to make a circle based on the point to use for the query and also to draw the circle

How do i get the (x,y) coordinates of the location where the user clicked (r.feature.get_geoJSON().geometry)

 

 

Highlighted
Technical Evangelist
Posts: 1,275
Registered: ‎09-11-2015

Re: Convert Geometry to x,y coordinates - URGENT

[ Edited ]

Hi Jane,

 

You are getting GeoJSON object in the response callback. If this is just about getting a single point, then it's quite simple:

 

$GP.map.draw({"type": "Point"},
    function (r) {
      var coords =  r.feature.get_geoJSON().geometry.coordinates;
      // coordinates order may vary depending on the CRS definition
      $GP.ui.info("x: " + coords[0] + ", y: " + coords[1]);
});

 

Does that help?

 

Jan

 

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Technical Evangelist
Posts: 1,275
Registered: ‎09-11-2015

Re: Convert Geometry to x,y coordinates - URGENT

[ Edited ]

This sample code can be run directly on the demo server, it draws a circle of certain diameter on the point the user clicked:

 

$GP.map.draw({"type": "Point"},
    function (r) {
      var coords =  r.feature.get_geoJSON().geometry.coordinates;
      // coordinates order may vary depending on the CRS definition
           
      $GP.map.draw({
          "type": "Feature",
          "geometry": {
              "type": "Polygon",
              "coordinates": [
                  [
                      [coords[0], coords[1], 0, 0, 1],
                      [coords[0] + 50000, coords[0] + 50000],
                      [coords[0], coords[1], 0, 0, 1]
                  ]
              ],
              "crsId": "EPSG:4326"
          },
          "properties": {}
      });
}

 

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: Convert Geometry to x,y coordinates - URGENT

Thanks you very much!  

var coords = r.feature.get_geoJSON().geometry.coordinates was the line of codei needed!

Is there some include file that i need to have access to words like "intersects" instead of using a 0 in a 

$GP.queries.add call?

I wish i could use that circle for my spatial query but i guess i will generate a many sided polygon from the center point and use that instead.

Now i just need to be able to access the attribute data of plant features that are selected by my query - i can do it manually within GP so I am optimistic!

Thanks again

Highlighted
Technical Evangelist
Posts: 1,275
Registered: ‎09-11-2015

Re: Convert Geometry to x,y coordinates - URGENT

[ Edited ]

I don't quite understand the question, but I guess it's related to your other topic here:

http://community.hexagongeospatial.com/t5/Developer-Discussions/Spatial-Queries/td-p/6130

 

I'm not aware about any additional "files" that could be useful for the analysis. Sorry.

 

Jan

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: Convert Geometry to x,y coordinates - URGENT

Thanks, yet it was related to my other questions - Just curious why i have to use "0" instead of "intersects" when specifying the filter operator for my query.    i do have my code working now  - i am generating a circle polygon from the center point since i couldn't use the circle definition on the query.

Highlighted
Super Contributor
Posts: 301
Registered: ‎02-09-2016

Re: Convert Geometry to x,y coordinates - URGENT

Please be aware that from Gepspatial Portal 2015 EP05, acoording to the product centre, the get_GeoJson() become asynchornous, so you should retrieve it from a callback.

 

Kind regards,

Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: Convert Geometry to x,y coordinates - URGENT

Got it!

Highlighted
Regular Contributor
Posts: 253
Registered: ‎05-01-2016

Re: Convert Geometry to x,y coordinates - URGENT

I've had lots of progress and am now including  custom tooltips on the features overlapping witht the circle.

All is working great except if the tooltips are drawn inside the circle (some are drawn outside since the features are large and many overlap with circle rather than being fully inside it) then the "over" action fails and the tooltips don't display.  I got around this by making the circle be drawn as a line string and actually giving the (x,y) coordinates to draw.  This would be ok except i can't get the thickness of the linestyle to work for my WMPS feature so the circle outline is too undefined - i wanted it to be thicker and in a darker color. Do i need to draw the circle as a line string or can i draw it as a polygon.  I can send a screenshot if it would be helpful...