Coder Social home page Coder Social logo

earthworm's Introduction

A simple .NET (4.x or 6.0) assembly that provides an object-relational mapping abstraction layer for geodatabase feature classes and tables. It converts features and rows into a (lazy) sequence of strongly-typed objects.

*You will need ArcGIS Desktop, Engine or Server 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8 or 10.9.

The ClickOnce installer is here:

http://jshirota.github.io/Earthworm/ORMappingDeploy.application

The library reference is here:

http://jshirota.github.io/Earthworm/Help/

The NuGet package is here:

http://nuget.org/packages/Earthworm

.NET 6:

Starting at Version 2.1, we support .NET 6.0 as well as .NET Framework 4.x.

The source code for this is a new branch: https://github.com/jshirota/Earthworm/tree/3.0

##Examples

This update uses the update cursor.

foreach (var city in cityFeatureClass.Map<City>(useUpdateCursor: true))
{
    city.POP2000 += 1;
    city.Update();
}

If you use the following static imports, you can define geometries much more succinctly.

using static Earthworm.Shape;

For example,

var state = new State
{
    STATE_NAME = "Test",
    Shape = Polygon(
        OuterRing(P(0, 0), P(0, 3), P(3, 3), P(3, 0)),
        InnerRing(P(1, 1), P(1, 2), P(2, 2), P(2, 1))
        )
};

state.ToKml().Save("test.kml");

This inserts a new record.

var toronto = new City
{
    AREANAME = "Toronto",
    POP2000 = 123,
    Shape = P(-79.5, 43.6)
};

toronto.InsertInto(cityFeatureClass);

This also inserts records. If you have many records to insert, this is more effective because all of the records are inserted via an inert cursor.

cityFeatureClass.Insert(manyCities);

Sometimes you have to dynamically access a field by name. That's OK. We support editing data that way, too.

city["hidden_field"] = 1234;
city.Update();

You need a workspace edit session? No problem.

try
{
    workspace.Edit(() =>
    {
        foreach (var city in cityFeatureClass.Map<City>(useUpdateCursor: true))
        {
            city.POP2000 = 0;
            city.Update();
        }

        throw new Exception("Dummy error!");
    });
}
catch (Exception ex)
{
    Console.WriteLine("Error occurred and rolled back.  " + ex.Message);
}

This returns an XElement.

toronto.ToKml()

So does this.

toronto.Shape.ToKml()

Many overloads available for KML, which I will discuss later.

cityFeatureClass.Map<City>().ToKml().Save("doc.kml");

Let's say you have a Windows Forms UI like this.

var cities = cityFeatureClass.Map<City>().ToList();

var f = new Form();
f.Controls.Add(new DataGridView
{
    DataSource = new BindingSource { DataSource = cities },
    Dock = DockStyle.Fill
});

Application.Run(f);

If you change an attribute value, IsDirty becomes true. This is because the mapped objects raise the ProperyChanged event on its own.

This creates a new feature class in inserts cities with more than 1 million people into it.

var cityFeatureClass = featureWorkspace.OpenFeatureClass("Cities");

featureWorkspace.CreateFeatureClass<City>("Cities2", esriGeometryType.esriGeometryPoint, 4326)
    .Insert(cityFeatureClass.Map<City>(new QueryFilter { WhereClause = "POP2000>1000000" }));

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.