|
POST
|
I have found a solution that works pretty good. For anyone who is interested: Here is a link to a JSON parser built speficially for VBA: GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA Using my code above, I tweaked it a bit to come up with this, which is working fairly well so far. Probably some adjustments to come, but so far, so good. Private Sub Command0_Click()
Dim httpReq As New MSXML2.ServerXMLHTTP
Dim fullAddress As String
fullAddress = txtNumber & " " & txtStreetName & " " & txtType & " " & txtDir & ", " & cboMunicipality
httpReq.Open "GET", "https://maps.durham.ca/arcgis/rest/services/Locators/ADDR_Locator/GeocodeServer/findAddressCandidates?Single Line Input=" & fullAddress & "&outfields=Score&f=json"
httpReq.send
Dim response As String
response = httpReq.responseText
Dim json As Object
Set json = JsonConverter.ParseJson(response)
Dim foundMatch As Boolean
Dim alternateAddress As Variant
Dim dimEd As Boolean
dimEd = False
On Error GoTo JSON_Handler:
For i = 1 To 5
If json("candidates")(i)("score") = 100 Then
foundMatch = True
MsgBox fullAddress & " is a valid address.", vbInformation, "Match Found"
Exit Sub
Else
If dimEd = True Then
ReDim Preserve alternateAddress(0 To UBound(alternateAddress) + 1) As String
Else
ReDim alternateAddress(0 To 0) As String
dimEd = True
End If
alternateAddress(UBound(alternateAddress)) = json("candidates")(i)("address") & " - Score = " & Round(json("candidates")(i)("score"), 2) & "%"
End If
Next i
JSON_Handler:
If IsEmpty(alternateAddress) Then
MsgBox "Provided address does not exist in our corporate address list. There are no similar matching addresses.", vbInformation, "Address Not Valid"
Exit Sub
End If
For i = 0 To UBound(alternateAddress)
Dim list As String
list = list & alternateAddress(i) & vbCr & vbCr
Next i
MsgBox "Provided address does not exist in our corporate address list. Here are some similar addresses:" & vbCr & vbCr & list, vbInformation, "Alternate Addresses and Geocode Score"
End Sub
... View more
02-08-2018
06:45 AM
|
0
|
0
|
1093
|
|
POST
|
Hi, I'm trying to figure out the best way to use an existing Locator service within an MS Access database for verifying that the address being typed in is actually valid. Within my MS Access database I can retrieve the 'score' from the locator service using some code like this: Private Sub Command0_Click()
Dim httpReq As New MSXML2.ServerXMLHTTP
httpReq.Open "GET", "https://maps.durham.ca/arcgis/rest/services/Locators/Durham_Locator/GeocodeServer/findAddressCandidates?SingleLine=66 Church Street, Ajax&outfields=Score&f=json"
httpReq.send
Dim response As String
response = httpReq.responseText
Set fs = CreateObject("Scripting.FileSystemObject")
Set thefile = fs.CreateTextFile(Application.CurrentProject.Path & "\geo.txt", True)
thefile.write (response)
thefile.Close
'MsgBox response
'MsgBox Application.CurrentProject.Path
End Sub Has anyone done this before? I'm not totally sure of the best approach from here. I guess I could scan the response to look for the score of all the matches, and let the user choose the best one?? I guess I'm just looking for some ideas. The formatting of the JSON that comes back is a bit foreign to me and I'm not sure of the best way to deal with it. Here is a sample of what I am getting back from the service: {"spatialReference":{"wkid":26917,"latestWkid":26917},"candidates":[{"address":"66 Church Street North, Ajax","location":{"x":656188.74132460123,"y":4857786.8273707693},"score":90.870000000000005,"attributes":{"Score":90.870000000000005}},{"address":"66 Church Street South, Ajax","location":{"x":656363.87805667717,"y":4857321.912464018},"score":90.870000000000005,"attributes":{"Score":90.870000000000005}},{"address":"66 Church St S, Ajax","location":{"x":656335.19874352403,"y":4857300.3138142293},"score":90.870000000000005,"attributes":{"Score":90.870000000000005}},{"address":"66 Church St S, Ajax","location":{"x":656337.24088169797,"y":4857318.2643990703},"score":90.870000000000005,"attributes":{"Score":90.870000000000005}}]} Or is there a totally different, better way that what I am thinking?? Thanks for any input!!
... View more
02-07-2018
12:29 PM
|
0
|
1
|
1323
|
|
POST
|
Hi Jay. I checked my settings, and it is already set to that. I will try to mess with the other settings there, but from what I have tried so far, no luck.... Thanks
... View more
02-06-2018
12:48 PM
|
0
|
0
|
562
|
|
POST
|
Hi, Yes, I have this same issue too running ArcPro 2.1.1. Running Windows 7 with all the proper drivers installed.
... View more
02-06-2018
12:18 PM
|
0
|
2
|
562
|
|
IDEA
|
I also agree that the PGDB format needs to be supported in ArcPro. We have many (ie. 1000's) of MXDs that have been created over the years that have PGDB connections in them. We find the PGDB much more user friendly than the FGDB format, especially if you want to get into the back end of the data and do some advanced querying that you cannot do through the ArcMap/Pro interface. What are we supposed to do? Convert all of our 1000's of PGDB files into the FGDB format?? That is not practical.
... View more
01-30-2018
06:58 AM
|
10
|
1
|
2831
|
|
POST
|
Hi Kory. Yes, I have seen this article, but it seems to only apply to new fields in a pop-up. So basically every user would have to set this up, whereas currently in ArcMap there is no additional configuration....it just works. Do you know if when modifying the pop-up for a layer if that is easily deploy-able enterprise wide? Or does the pop-up have to modified individually for each user?? Thanks,
... View more
01-26-2018
10:02 AM
|
0
|
1
|
3142
|
|
POST
|
Hi, In ArcMap all of our hyperlinks to internal drive mappings worked. You would just identify the feature, and click on the link. In ArcPro, the pop-up does not seem to recognize that the drive mapping is a hyperlink and it just displays as text. Is there a way to fix this?? See screenshot below.
... View more
01-26-2018
08:30 AM
|
1
|
5
|
4068
|
|
POST
|
Hi Narelle. Wow!! Thanks for taking the time to put all of that together. That definitely helps to clarify how editing in ArcPro works. I still need to sit down and work through making some changes to mine, but this will certainly help me optimize my code so it runs a bit smoother. I'm really just a part-time coder, converting the code in a bunch of ArcMap tools so they work in ArcPro but I'm always up for making things work better than before. I'll work on what you mentioned and post an further questions here. Thanks!!
... View more
01-10-2018
05:24 AM
|
0
|
0
|
1928
|
|
POST
|
Hi Sean, Yes, I have tried that before (see this post: https://community.esri.com/thread/205610-cannot-undo-after-edits-made ) but was not successful. In my case, I am looking to have all the edits created in the loop under one operation in the Undo stack. (ie. 100 edits, but just click Undo once to undo them all). My method seems to be working, but it seems a but counter-intuitive to have to do a 'fake' edit before entering the loop where all the real edits are made.
... View more
01-08-2018
12:16 PM
|
0
|
0
|
1928
|
|
POST
|
Hi Narelle, Here is my code now, and it seems to work. Again, I'm not really sure if this is the recommended way of dealing with the ChainedEditOperation in a looping situation, but it seems to work. private void btnSave_Click(object sender, EventArgs e)
{
try
{
//Give the user a chance to get out.
if (ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Are you sure you want to update all the selected layers?", "Update Selected Features?", System.Windows.MessageBoxButton.YesNo ) == System.Windows.MessageBoxResult.No)
return;
this.Cursor = Cursors.WaitCursor;
//Create a list of all the selected layers (since we cannot access Form controls in a QueuedTask)
//var updateLayers = lstLayers.Items.Cast<String>().ToList();
QueuedTask.Run(() =>
{
Map map = MapView.Active.Map;
FeatureLayer firstLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.IndexOf(lstLayers.Items[0].ToString(), StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();
//Create the MAIN edit operation...this will show up on the Undo Stack
var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
editOperation.Name = "Update Multiple Features";
editOperation.EditOperationType = ArcGIS.Desktop.Editing.EditOperationType.Long;
var inspSetup = new ArcGIS.Desktop.Editing.Attributes.Inspector();
bool firstEdit = false; //Create this to track the 'blank' edit
//Go through each layer in the Layers listbox
foreach (string layer in lstLayers.Items)
{
var currentLayer = map.FindLayers(layer).FirstOrDefault() as BasicFeatureLayer;
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
//Make a 'blank' edit, so that it triggers the ChainedEditOperation to work properly, later in the code
if (firstEdit == false)
{
inspSetup.Load(firstLayer, selectedOIDs.First<long>());
editOperation.Modify(inspSetup);
editOperation.Execute();
firstEdit = true;
}
foreach (var oid in selectedOIDs)
{
//Create the chained edit for the Undo stack
var chainedOp = editOperation.CreateChainedOperation();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
insp.Load(currentLayer, oid); //use the current selected OBJECTID as you go through the loop of selected features
for (int i = 0; i < gridFields.Rows.Count; i++)
{
if (gridFields.Rows[i].Cells[1].Value != null)
{
insp[gridFields.Rows[i].Cells[0].Value.ToString()] = gridFields.Rows[i].Cells[1].Value;
}
}
//Save the edits and commit the changes.
//This will update the ChainedEditOperation, so it only shows up once in the Undo Stack
chainedOp.Modify(insp);
chainedOp.Execute();
}
}
}
); //end of QueuedTask
}
catch
{
}
finally
{
this.Cursor = Cursors.Default;
}
} Thanks again for your assistance!!
... View more
01-08-2018
06:08 AM
|
0
|
2
|
1928
|
|
POST
|
Hi Narelle, Thanks for responding and the explanation of what is going wrong. You are correct; the first edit operation is coming up as FALSE. Can you possibly explain how the ChainedOperation should would in a looping situation? I have done this before in a previous tool I created, and I guess I got lucky in that it works. All of the samples I have found for ChainedOperation use a linear progression of code, so it's easy to see how it works, but in a looping situation I am not sure how to code that first edit that seems to trigger the rest of the ChainedEdits......does that make sense?? I'm not sure the way I am doing it, with the 'blank' edit, is really the proper way to do it.
... View more
01-08-2018
05:55 AM
|
0
|
0
|
1928
|
|
POST
|
I have an EditOperation that runs on the _Click event of a form. I'm pretty sure I have the ChainedEditOperation setup properly, as I have set this up previously in another tool I have made that work successfully. This is my first time trying an EditOperation of a Form event. What is happening is that edits are happening, but not showing up on the Undo Stack. Does anyone know if there are issues with an EditOperation run on a Form event that may cause problems?? I have posted my code below, as well as the windows Form to help provide some context: Basically it gives the user the ability to update common fields in the selected features of multiple feature classes, and the code below is for the Save button. private void btnSave_Click(object sender, EventArgs e)
{
try
{
//Give the user a chance to get out.
if (ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Are you sure you want to update all the selected layers?", "Update Selected Features?", System.Windows.MessageBoxButton.YesNo ) == System.Windows.MessageBoxResult.No)
return;
this.Cursor = Cursors.WaitCursor;
QueuedTask.Run(() =>
{
Map map = MapView.Active.Map;
FeatureLayer firstLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.IndexOf(lstLayers.Items[0].ToString(), StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();
//Create the MAIN edit operation...this will show up on the Undo Stack
var editOperation = new ArcGIS.Desktop.Editing.EditOperation();
editOperation.Name = "Update Multiple Features";
editOperation.EditOperationType = ArcGIS.Desktop.Editing.EditOperationType.Long;
//Make a 'blank' edit, so that it triggers the ChainedEditOperation to work properly, later in the code
var inspSetup = new ArcGIS.Desktop.Editing.Attributes.Inspector();
inspSetup.Load(firstLayer, 1);
editOperation.Modify(inspSetup);
editOperation.Execute();
//Go through each layer in the Layers listbox
foreach (string layer in lstLayers.Items)
{
//MessageBox.Show(layer);
var currentLayer = map.FindLayers(layer).FirstOrDefault() as BasicFeatureLayer;
var selection = currentLayer.GetSelection();
IReadOnlyList<long> selectedOIDs = selection.GetObjectIDs();
foreach (var oid in selectedOIDs)
{
//Create the chained edit for the Undo stack
var chainedOp = editOperation.CreateChainedOperation();
var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
insp.Load(currentLayer, oid); //use the current selected OBJECTID as you go through the loop of selected features
for (int i = 0; i < gridFields.Rows.Count; i++)
{
if (gridFields.Rows[i].Cells[1].Value != null)
{
insp[gridFields.Rows[i].Cells[0].Value.ToString()] = gridFields.Rows[i].Cells[1].Value;
}
}
//Save the edits and commit the changes.
//This will update the ChainedEditOperation, so it only shows up once in the Undo Stack
chainedOp.Modify(insp);
chainedOp.Execute();
}
}
}
); //end of QueuedTask
}
catch
{
}
finally
{
this.Cursor = Cursors.Default;
}
}
... View more
01-05-2018
11:28 AM
|
0
|
7
|
2197
|
|
POST
|
I need to access a ListBox control while also performing an action requiring a QueuedTask. When access the SelectedItems on the ListBox, I get an error about the ListBox being access outside of the thread that created it. What are the best ways to get around this? Should I just save the SelectedItems to a List before entering the QueuedTask, or is there a way to access Form controls while in the QueuedTask?? QueuedTask.Run(() =>
{
Map map = MapView.Active.Map;
foreach (string layerName in lstLayers.SelectedItems) //This is where I get the error
{
FeatureLayer currentLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.IndexOf(layerName, StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();
currentLayer.ClearSelection();
}
}
); //end of Queued Task
... View more
01-04-2018
05:54 AM
|
0
|
0
|
691
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 08-18-2023 08:57 AM | |
| 1 | 04-19-2018 05:53 AM | |
| 1 | 04-13-2018 10:07 AM | |
| 1 | 04-13-2018 10:04 AM | |
| 1 | 04-13-2018 05:56 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-20-2025
03:53 PM
|