Maptitude GISDK Help

Using the CaliperForm.Connection.Gisdk Class: Find_Nearest_Features()

This example opens a connection to the GISDK environment, finds the nearest features to a coordinate, and closes the connection to the GISDK environment:

 

C# Example

using System;

using System.Collections.Generic;

using System.Text;

using CaliperForm;

///

/// Select all landmark point features in a circle near a specific geographic coordinate.

///

static void Find_Nearest_Features() {

    CaliperForm.Connection Conn = new CaliperForm.Connection

        { MappingServer = mapping_product };

    Boolean opened = false;

    try {

        opened = Conn.Open(log_file);

        if (opened) {

            dynamic dk = Conn.Gisdk;

            // Locate by radius landmark points near located_coord

            dynamic located_coord = dk.Coord((int) (-71.071359 * 1000000.0) , (int)

                ( 42.353844 * 1000000.0)); // Downtown Boston

            Dictionary<String, Object> region_prefs =

                Cast.ToDictionary(dk.Macro("Get Geocoding Preferences"));

            if (region_prefs == null) {

                Console.Out.WriteLine("Macro 'Get Geocoding Preferences' returned null");

                Conn.Close();

                return;

            }

            string region_file = region_prefs["region_file"] as string;

            if (region_file != null) {

                string data_directory =

                    System.IO.Path.GetDirectoryName(region_file);

                string map_wizard_map_file = data_directory +

                    "\\Map Wizard Maps\\MapWizardUSMap.map";

                // Open the map wizard map witht the layers for this country package

                var map_options = new OptionsArray();

                map_options["Auto Project"] = "true";

                // path used to look for layers used in the map, before other locations

                // usually searched for

                map_options["Force Directory"] = data_directory;

                string map_name = dk.OpenMap(map_wizard_map_file, map_options);

                if (map_name == null) {

                    Console.Out.WriteLine("Cannot open map wizard map file "

                        + map_wizard_map_file + ". Perhaps some layers are missing?");

                    Conn.Close();

                    return;

                }

                var search_area = dk.Circle(located_coord, (double)1.0);

                // 3 Current Map Units (Mile, Kilometers,...)

                string layer_name = "Landmark";

                dk.SetLayer(layer_name);

                var opts = new OptionsArray();

                opts["Inclusion"] = "Intersecting";

                opts["Max"] = 50;

                opts["Display"] = "False";

                opts["Auto Redraw"] = "False";

                int n_found = dk.SelectByCircle("Near Coordinate", "several", search_area, opts);

                if (n_found > 0) {

                    string view_set = layer_name + "|Near Coordinate";

                    object[] fields = dk.GetFields(layer_name, "All");

                    var field_names = fields[0] as object[];

                    var field_specs = fields[1] as object[];

                    object[] sort_order = null;

                    object[] options = null;

                    string order = "Row";

                    string first_record = dk.GetFirstRecord(view_set, null);

                    string query = Convert.ToString(n_found) + " " + layer_name +

                        " Features Near Coordinate: " + Convert.ToString((double)

                        located_coord.Lat / 1000000.00) + "," + Convert.ToString((double)

                        located_coord.Lon / 1000000.00) ;

                    Console.Out.WriteLine(query);

                    Console.Out.WriteLine(string.Join(",", field_names));

                    object[] cells;

                    foreach (object row in dk.GetRecordsValues(view_set, first_record,

                        field_names, sort_order, n_found, order, null)) {

                        cells = row as object[];

                        if (cells != null) {

                            string row_values = string.Join(",", cells);

                            Console.Out.WriteLine(row_values);

                        }

                    }

                } else {

                    Console.Out.WriteLine("No " + layer_name + " Features Found Near Address.");

                }

            }

            Conn.Close();

        }

    } catch (System.Exception error) {

        Console.Out.WriteLine(error.Message);

    }

}

 

For more information, see:

Getting Started with CaliperForm

Using the CaliperForm.Connection Class

Using the GISDK Extension Engine In-Process API

 

See also these specific C# examples for:

Opening a Map

Opening a Table

Geocoding Addresses

Geocoding a Table

Calculating a Route

 

 

©2025 Caliper Corporation www.caliper.com