Hexagon Geospatial
MENU

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: 248
Registered: ‎05-01-2016

A subroutine to find all parcels intersecting with a user drawn line - it works at last!

[ Edited ]

Posting the code here - took me a while to get everything right!

 

 

     function SelectByLine() {
            style = new Intergraph.WebSolutions.Core.WebClient.Platform.Style.AreaStyle(null, {
                styles: [{
                    type: "SimpleLineStyle",
                    color: "#00ff00",
                    size: 3
                }, {
                    type: "SimpleFillStyle",
                    color: "#0000ff",
                    translucency: 0.7
                }]
            });

            function createAnalysis(geometry) {
                if (!Date.now) {
                    Date.now = function () { return new Date().getTime(); }
                }

                
                var coords = geometry.coordinates;
            
         var geometry2 = geometry.coordinates[0].reduce(function (prev, current) {
               return prev = prev.concat(current)
           }, []),
           ab  = JSON.stringify([geometry]).slice(37,-23);
           $GP.ui.info(ab);

           $GP.ui.info("# of points entered = " + coords.length);
           var queryName = "SelectByLine_" + coords.length + " Pts";
              
              var coordArray = JSON.parse("[" + ab + "]");
      
                $GP.queries.add({
                    queryName: queryName,
                    definitionName: "MapPublisher",
                    style: style,
                    featureClassId: "34644522FD66F454EFD7A34AC7AA1F373C41D430|Parcels_with_Labels",
                    url: "http://cthse-gis/JD1/MapService.svc",
                    applicationId: "JD1_GeomediaWebMap_Source",
                    addToLegend: true,

                    filters: [{
                        type: "spatial",
                        operator: 0,
                        complement: false,
                        operands: [
                                {
                                    "type": "LineString",
                                    "coordinates": coordArray,
                                   
                                    "crsId": "EPSG:3486"
                                }
                        ]

                    }]
                },
                function (result) {
                    if (result.updated) {
                        $GP.ui.info("Analysis updated");

                        return;
                    }
                    $GP.queries.find({
                        analysisId: result.analysisId,
                    }, function (result2) {

                        result2.analysis.getData(function (data) {

                            result2.analysis.addToDataView();
                        });
                    });
                }
            );
            }
            $GP.legend.find({}, function (ret) {


            });

            $GP.map.draw.clear();
            $GP.ui.info("Click to draw line");

            $GP.map.draw({ "type": "LineString" },
                function (r) {
                    var coords = r.feature.get_geoJSON().geometry.coordinates;
                    // coordinates order may vary depending on the CRS definition

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

                });
            
        };

 

 

Staff
Posts: 294
Registered: ‎11-05-2015

Re: A subroutine to find all parcels intersecting with a user drawn line - it works at last!

Awesome! Glad you got it working, geoquery!
Super Contributor
Posts: 301
Registered: ‎02-10-2016

Re: A subroutine to find all parcels intersecting with a user drawn line - it works at last!

Hi geoquery,

 

Glad that you make it work. I used to have so much trouble with building analysis queries, so this is a good example to use as reference and learn from. I just wonder whether you thought about using SDK API selection function and making use of core selection, we could search the target legend entry and then feed it to the function mapService.findFeatures(....) and then manually handle its callback to get the data. We make use of it to implement selection features in multiple layers and it works great with wfs services.

 

Kind regards,

 

 

Regular Contributor
Posts: 248
Registered: ‎05-01-2016

Re: A subroutine to find all parcels intersecting with a user drawn line - it works at last!

Thanks! - i tried using the selection functions first but couldn't get it to work when specifying a feature id (from a WMPS connection)

If there is an example i could modify, i'd try it out...The query was good because it was easy to to add the records to the dataview

Polls
Please register to vote
Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.