Giter VIP home page Giter VIP logo

arcgis.pcl's Introduction

Icon

ArcGIS.PCL

Use ArcGIS Server REST resources without an official SDK more information.

It can also be used for just working with types and as well as some ArcGIS Server types you can also use GeoJSON FeatureCollections with the ability to convert GeoJSON <-> ArcGIS Features.

Typical use case would be the need to call some ArcGIS REST resource from server .NET code or maybe a console app. Rather than having to fudge a dependency to an existing SDK you can use this. Works with .NET for Windows Store apps, .NET framework 4.5, Silverlight 5, Windows Phone 8 and higher and Xamarin iOS and Android.

Since the serialization is specific to your implementation you will need to create an ISerializer to use in your gateway. There are NuGet packages created for 2 of these called ArcGIS.PCL.JsonDotNetSerializer and ArcGIS.PCL.ServiceStackV3Serializer. To use one of these add a reference using NuGet then call the static Init() method e.g. ArcGIS.ServiceModel.Serializers.JsonDotNetSerializer.Init(). This will create an ISerializer instance and override the SerializerFactory.Get() method so that it is returned when requested. This also means that you no longer have to pass the ISerializer to your gateway or token providers when initialising them, though you can still use this mechanism if you prefer.

Supports the following as typed operations:

  • CheckGenerateToken - create a token automatically via an ITokenProvider
  • Query<T> - query a layer by attribute and / or spatial filters
  • QueryForCount - only return the number of results for the query operation
  • QueryForIds - only return the ObjectIds for the results of the query operation
  • Find - search across n layers and fields in a service
  • ApplyEdits<T> - post adds, updates and deletes to a feature service layer
  • Geocode - single line of input to perform a geocode usning a custom locator or the Esri world locator
  • Suggest - lightweight geocode operation that only returns text results, commonly used for predictive searching
  • ReverseGeocode - find location candidates for a input point location
  • Simplify<T> - alter geometries to be topologically consistent
  • Project<T> - convert geometries to a different spatial reference
  • Buffer<T> - buffers geometries by the distance requested
  • DescribeSite - returns a url for every service discovered
  • Ping - verify that the server can be accessed

Some example of it in use for server side processing in web sites

The code for these can be seen at ArcGIS.PCL-Sample-Projects

See some of the tests for some example calls.

###Gateway Use Cases

// ArcGIS Server with non secure resources
var gateway = new PortalGateway("http://sampleserver3.arcgisonline.com/ArcGIS/");

// ArcGIS Server with secure resources
var secureGateway = new SecureArcGISServerGateway("http://serverapps10.esri.com/arcgis", "user1", "pass.word1");

// ArcGIS Server with secure resources and token service at different location
var otherSecureGateway = new PortalGateway("http://sampleserver3.arcgisonline.com/ArcGIS/", tokenProvider: new TokenProvider("http://serverapps10.esri.com/arcgis", "user1", "pass.word1"));

// ArcGIS Online either secure or non secure
var arcgisOnlineGateway = new ArcGISOnlineGateway();
 
var secureArcGISOnlineGateway = new ArcGISOnlineGateway(tokenProvider: new ArcGISOnlineTokenProvider("user", "pass"));

var secureArcGISOnlineGatewayOAuth = new ArcGISOnlineGateway(tokenProvider: new ArcGISOnlineAppLoginOAuthProvider("clientId", "clientSecret"));

Converting between ArcGIS Feature Set from hosted FeatureService and GeoJSON FeatureCollection

static Dictionary<String, Func<String, FeatureCollection<IGeoJsonGeometry>>> _funcMap = new Dictionary<String, Func<String, FeatureCollection<IGeoJsonGeometry>>>
{
    { GeometryTypes.Point, (uri) => new ProxyGateway(uri).GetGeoJson<Point>(uri) },
    { GeometryTypes.MultiPoint, (uri) => new ProxyGateway(uri).GetGeoJson<MultiPoint>(uri) },
    { GeometryTypes.Envelope, (uri) => new ProxyGateway(uri).GetGeoJson<Extent>(uri) },
    { GeometryTypes.Polygon, (uri) => new ProxyGateway(uri).GetGeoJson<Polygon>(uri) },
    { GeometryTypes.Polyline, (uri) => new ProxyGateway(uri).GetGeoJson<Polyline>(uri) }
};

...

var layer = new ProxyGateway(uri).GetAnything(uri.AsEndpoint());
if (layer == null || !layer.ContainsKey("geometryType")) throw new HttpException("You must enter a valid layer url.");
return _funcMap[layer["geometryType"]](uri);

...

public class AgsObject : JsonObject, IPortalResponse
{
    [System.Runtime.Serialization.DataMember(Name = "error")]
    public ArcGISError Error { get; set; }
}

public class ProxyGateway : PortalGateway
{
    public ProxyGateway(String rootUrl)
        : base(rootUrl)
    { }

    public Task<AgsObject> GetAnything(ArcGISServerEndpoint endpoint)
    {
        return Get<AgsObject>(endpoint);
    }

    public async Task<FeatureCollection<IGeoJsonGeometry>> GetGeoJson<T>(String uri) where T : IGeometry
    {
        var result = await Query<T>(new Query(uri.AsEndpoint()));
        result.Features.First().Geometry.SpatialReference = result.SpatialReference;
        var features = result.Features.ToList();
        if (result.SpatialReference.Wkid != SpatialReference.WGS84.Wkid)
            features = Project<T>(features, SpatialReference.WGS84);
        return features.ToFeatureCollection();
    }
}

Converting between GeoJSON FeatureCollection and ArcGIS Feature Set

static Dictionary<String, Func<String, List<Feature<IGeometry>>>> _funcMap = new Dictionary<String, Func<String, List<Feature<IGeometry>>>>
{
    { "Point", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonPoint>>(data).ToFeatures<GeoJsonPoint>() },
    { "MultiPoint", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonLineString>>(data).ToFeatures<GeoJsonLineString>() },
    { "LineString", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonLineString>>(data).ToFeatures<GeoJsonLineString>() },
    { "MultiLineString", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonLineString>>(data).ToFeatures<GeoJsonLineString>() },
    { "Polygon", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonPolygon>>(data).ToFeatures<GeoJsonPolygon>() },
    { "MultiPolygon", (data) => JsonSerializer.DeserializeFromString<FeatureCollection<GeoJsonMultiPolygon>>(data).ToFeatures<GeoJsonMultiPolygon>() }
};

...

return _funcMap["Point"](data);

Usage

If you have NuGet installed, the easiest way to get started is to install via NuGet:

PM> Install-Package ArcGIS.PCL

On Xamarin you can add the ArcGIS.PCL component from the component store or use the NuGet addin and add it from there.

Of course you can also get the code from this site.

Icon

Icon made by Freepik from www.flaticon.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.