Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
AnswerRe: DataGridView Calculations Pin
Mycroft Holmes6-May-09 22:12
professionalMycroft Holmes6-May-09 22:12 
QuestionI have problems in word automation Pin
Roshanakak6-May-09 21:09
Roshanakak6-May-09 21:09 
QuestionPBX VOIP Pin
imranliaqat6-May-09 20:16
imranliaqat6-May-09 20:16 
JokeRe: PBX VOIP Pin
Dino Mulahusic6-May-09 20:47
professionalDino Mulahusic6-May-09 20:47 
QuestionUsing open office in .net Pin
tauras816-May-09 19:53
tauras816-May-09 19:53 
AnswerRe: Using open office in .net Pin
N a v a n e e t h6-May-09 20:44
N a v a n e e t h6-May-09 20:44 
AnswerRe: Using open office in .net Pin
Rajesh R Subramanian7-May-09 0:34
professionalRajesh R Subramanian7-May-09 0:34 
QuestionSolving vehicle routing problem in .NET (C#) Pin
Andisheh_K6-May-09 19:49
Andisheh_K6-May-09 19:49 
I am developing an application in .NET to solve VRP, without using ArcGIS Server, but I can not find a complete sample code, I used other samples such as routesolver and get help from them, but I faced Exception in INASolver.Solve that shows I didn't load NAClasses correctly, I will be really thankfull if you could help me.Please!!!Frown | :(

I get COMExecption on the line : INASolver.Solve(...), details:Invalid input in NAClass

my code:

IAoInitialize pAoInitialize = new AoInitializeClass();
pAoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
pAoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork);

IWorkspaceFactory ipWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
m_pWorkspace = ipWorkspaceFactory.OpenFromFile(SHAPE_WORKSPACE, 0);

IFeatureWorkspace pFWorkspace = m_pWorkspace as IFeatureWorkspace;
IWorkspaceExtensionManager pWorkspaceExtensionManager = m_pWorkspace as IWorkspaceExtensionManager;

UID pUID = new UIDClass();
pUID.Value = "esriGeoDatabase.NetworkDatasetWorkspaceExtension";

IDatasetContainer2 pDatasetContainer2;
pDatasetContainer2 = pWorkspaceExtensionManager.FindExtension(pUID) as IDatasetContainer2;

m_pNetworkDataset = pDatasetContainer2.get_DatasetByName(esriDatasetType.esriDTNetworkDataset, NETWORK_DATASET) as INetworkDataset;
INALayer pNALayer = CreateVRPAnalysisLayer("Vehicle Routing Problem", m_pNetworkDataset);

String INPUT_DEPOTS = "DistributionCenters";
String INPUT_ORDERS = "Stores";
// String INPUT_ROUTES = "Routes";

INAContext pNAContext;
pNAContext = pNALayer.Context;
INAContextEdit vrpNAContextEdit = pNAContext as INAContextEdit;
vrpNAContextEdit.Bind(pNALayer.Context.NetworkDataset, null);

//Load Depots

m_pInputFClass = pFWorkspace.OpenFeatureClass(INPUT_DEPOTS);            
ICursor InputDepotsCursor = m_pInputFClass.Search(new QueryFilterClass(), false) as ICursor;
LoadAnalysisLayer("Depots", pNAContext, InputDepotsCursor);

//Load Orders
m_pInputFClass = pFWorkspace.OpenFeatureClass(INPUT_ORDERS);
ICursor InputOrdersCursor = m_pInputFClass.Search(new QueryFilterClass(), false) as ICursor;
LoadAnalysisLayer("Orders", pNAContext, InputOrdersCursor);

//Load Routes
IMap vrpMap = axMapControl1.Map;
ITable routesInputTable = GetStandaloneTable("Vehicles", vrpMap).Table;
ICursor InputRoutesCursor = routesInputTable.Search(new QueryFilterClass(), true) as ICursor;
LoadAnalysisLayer("Routes", pNAContext, InputRoutesCursor);


//Solve
INASolver pSolver;
pSolver = pNAContext.Solver;
INAVRPSolver vrpSolver = pSolver as INAVRPSolver;
vrpSolver.GenerateInternalRouteContext = true; // Required for true-shape and directions
vrpSolver.DefaultDate = DateTime.Today;        // Set the default date to be today

pSolver.Solve(pNAContext, new GPMessagesClass(), new CancelTrackerClass());

private void LoadAnalysisLayer(string ClassName, INAContext context, ICursor cursor)
{
    INAClass pNAClass;
    pNAClass = context.NAClasses.get_ItemByName(ClassName) as INAClass;
    //pRoutesFC = pNAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;

    //Load 
    INAClassFieldMap pNAClassFieldMap = new NAClassFieldMapClass();
    pNAClassFieldMap.set_MappedField("Name", SHAPE_INPUT_NAME_FIELD);

    INAClassLoader pNALoader = new NAClassLoaderClass();
    pNALoader.Locator = context.Locator;
    pNALoader.NAClass = pNAClass;
    pNALoader.FieldMap = pNAClassFieldMap;

    int rowsInCursor = 0;
    int rowsLocated = 0;
    pNALoader.Load(cursor, new CancelTrackerClass(), ref rowsInCursor, ref rowsLocated);
}

QuestionRe: Solving vehicle routing problem in .NET (C#) Pin
Andisheh_K9-May-09 1:39
Andisheh_K9-May-09 1:39 
Questionconvert.ToInt32 Pin
yueru6-May-09 18:57
yueru6-May-09 18:57 
AnswerRe: convert.ToInt32 Pin
dotnetmember6-May-09 19:54
dotnetmember6-May-09 19:54 
GeneralRe: convert.ToInt32 Pin
battulga_dddddd6-May-09 20:42
battulga_dddddd6-May-09 20:42 
AnswerRe: convert.ToInt32 Pin
Spunky Coder6-May-09 19:55
Spunky Coder6-May-09 19:55 
AnswerRe: convert.ToInt32 Pin
tolw6-May-09 19:58
tolw6-May-09 19:58 
GeneralRe: convert.ToInt32 Pin
yueru6-May-09 21:20
yueru6-May-09 21:20 
GeneralRe: convert.ToInt32 Pin
Guffa6-May-09 21:47
Guffa6-May-09 21:47 
GeneralRe: convert.ToInt32 Pin
yueru6-May-09 22:05
yueru6-May-09 22:05 
GeneralRe: convert.ToInt32 Pin
Guffa7-May-09 0:49
Guffa7-May-09 0:49 
Questioncatch an object returned by java webservice in c# application. Pin
prasadbuddhika6-May-09 17:39
prasadbuddhika6-May-09 17:39 
AnswerRe: catch an object returned by java webservice in c# application. Pin
Spunky Coder6-May-09 20:00
Spunky Coder6-May-09 20:00 
QuestionBackup Program Pin
nsimbu6-May-09 14:08
nsimbu6-May-09 14:08 
QuestionListView Pin
al3xutzu006-May-09 12:26
al3xutzu006-May-09 12:26 
AnswerRe: ListView Pin
Henry Minute6-May-09 13:37
Henry Minute6-May-09 13:37 
AnswerRe: ListView Pin
Roberto Ho6-May-09 13:50
Roberto Ho6-May-09 13:50 
AnswerRe: ListView Pin
nsimbu6-May-09 13:51
nsimbu6-May-09 13:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.