Find frontage street polyline given a street address - arcgis

I have an app whereby users select parcels of land based on shapefile information. How can I return the associated street polyline location (lat, long)? I want to be able to locate the center of the street and its extents in front of this parcel. Refer to the image below the parcel is in blue and the street polyline I am interested in is in red.
If I could be pointed towards which Esri javascript method or class I could use then I can figure out the rest

Assuming that you have a Road FeatureLayer, what you could do is to spatial query it using the parcel geometry. In order to do that you can use queryFeatures method. You can add a buffer distance in order to get the roads that are around the parcel. Something like this,
let query = roadsFeatureLayer.createQuery();
query.geometry = parcelGeometry; // the parcel polygon geometry
query.distance = 10;
query.units = "meters";
query.spatialRelationship = "intersects";
query.returnGeometry = true;
query.outFields = ["*"];
roadsFeatureLayer.queryFeatures(query)
.then(function(response){
// returns a feature set with the roads features that
// intersect the 10 meters buffered parcel polygon geometry
});
Now, the result includes a set of roads. The decision of wich one you need, is another problem like #seth-lutske mention in the comments.
ArcGIS JS API - FeatureLayer queryFeatures

Related

How to get all the substates from a country in OSMNX?

What would be the code to easily get all the states (second subdivisions) of a country?
The pattern from OSMNX is, more or less:
division
admin_level
country
2
region
3
state
4
city
8
neighborhood
10
For an example, to get all the neighborhoods from a city:
import pandas as pd
import geopandas as gpd
import osmnx as ox
place = 'Rio de Janeiro'
tags = {'admin_level': '10'}
gdf = ox.geometries_from_place(place, tags)
The same wouldn't apply if one wants the states from a country?
place = 'Brasil'
tags = {'admin_level': '4'}
gdf = ox.geometries_from_place(place, tags)
I'm not even sure this snippet doesn't work, because I let it run for 4 hours and it didn't stop running. Maybe the package isn't made for downloading big chunks of data, or there's a solution more efficient than ox.geometries_from_place() for that task, or there's more information I could add to the tags. Help is appreciated.
OSMnx can potentially get all the states or provinces from some country, but this isn't a use case it's optimized for, and your specific use creates a few obstacles. You can see your query reproduced on Overpass Turbo.
You're using the default query area size, so it's making thousands of requests
Brazil's bounding box intersects portions of overseas French territory, which in turn pulls in all of France (spanning the entire globe)
OSMnx uses an r-tree to filter the final results, but globe-spanning results make this index perform very slowly
OSMnx can acquire geometries either via the geometries module (as you're doing) or via the geocode_to_gdf function in the geocoder module. You may want to try the latter if it fits your use case, as it's extremely more efficient.
With that in mind, if you must use the geometries module, you can try a few things to improve performance. First off, adjust the query area so you're downloading everything with one single API request. You're downloading relatively few entities, so the huge query area should still be ok within the timeout interval. The "intersecting overseas France" and "globe-spanning r-tree" problems are harder to solve. But as a demonstration, here's a simple example with Uruguay instead. It takes 20 something seconds to run everything on my machine:
import osmnx as ox
ox.settings.log_console = True
ox.settings.max_query_area_size = 25e12
place = 'Uruguay'
tags = {'admin_level': '4'}
gdf = ox.geometries_from_place(place, tags)
gdf = gdf[gdf["is_in:country"] == place]
gdf.plot()

Querying a feature layer with a large amount of points

Working in ArcGIS JS API 4.22:
I am trying to query a feature layer (polygons) with a large amount of points (~1000) in order to find which polygons the points intersect with (by name only, no need for geometries. Doing this with a loop for each point individually is extremely slow and errors out. I've tried condensing the points to a multipoint geometry in hopes of speeding the process to no avail. Is there a solution to this that I am just overlooking?
Added code:
const layer = new FeatureLayer({
url: "https://arcgis-server.lsa.umich.edu/arcgis/rest/services/IFR/glahf_classification_poly/MapServer/0",
outFields: ["AEU_Code"],
});
//gets a server error at about 250 points
var multipoint = new Multipoint({
points: [
[-86, 45],
[-85, 47],
[-84, 49]
]
});
const query = new Query();
query.geometry = multipoint;
query.outSpatialReference = { wkid: 102100 };
query.returnGeometry = false;
query.outFields = ["AEU_Code"];
layer.queryFeatures(query).then(function (results) {
console.log(results.features); // prints the array of features to the console
});
Thanks!
So you have two separate layers in this situation right? A polygon layer and a points layer? Use the pairwise intersect tool, it should result in an feature class where the attribute table has all of your points along with the fields from the polygon layer they intersect with. 1000 points really isn't that many, this should not be very computationally intense.
If this is not what you're doing can you be more descriptive with the data you have and what you are trying to accomplish?
The other way I interpret the question is that you already have the feature layer I described, but are trying to query it in some way. If this is the case can you elaborate on what you are trying to glean from the data? I don't understand why you would need to query each point individually.
I check the polygon service and it has 77 features. If you can load all the polygons in the view, then one possible option is to do the intersection in the client instead of the server. In this way at least you avoid timeout issues, you will have to time it to see how long it takes.
In order to to the intersection in the client use the layer view instead of the layer, ArcGIS JS API - FeatureLayerView queryFeatures.

OSMnx - tags missing in graph edges

I'm trying to detect all the streets in a city were bikes can ride. To do this I want to include the footways that include the tag "bicycle":"yes", but I can't find it in the data downloaded with OSMnx.
For example the edge with id 45031879 as an xml downloaded directly from openstreetmap website appears like this:
<way id="45031879" visible="true" version="4" changeset="64616340" timestamp="2018-11-18T10:34:12Z" user="livmilan" uid="712033">
<nd ref="571102337"/>
...
<nd ref="1587102704"/>
<tag k="bicycle" v="yes"/> <=====
<tag k="highway" v="footway"/>
</way>
But in the edges when downloaded with OSMnx with command graph = ox.graph_from_place(place, network_type='all')) it appears like this:
{'osmid': 45031879, 'highway': 'footway', 'oneway': False, 'length': 22.818, 'geometry': <shapely.geometry.linestring.LineString object at 0x00000170F3F112C8>}
It appears that the bicycle information went lost. Is there a way to download the additional tags with osmnx?
Thank you
Configure the useful_tags_way setting to add additional OSM way tags to retain as graph edge attributes:
import osmnx as ox
ox.config(log_console=True, use_cache=True,
useful_tags_way = ox.settings.useful_tags_way + ['bicycle'])
place = 'Berkeley, CA, USA'
G = ox.graph_from_place(place, network_type='bike')
edges = ox.graph_to_gdfs(G, nodes=False)
'bicycle' in edges.columns #True

Service Area Polygon Geometry

I need to get a service area polygon (graphics) for inserting it into a query as geometry.
This is a piece of code (a serviceAreaTask)
serviceAreaTask.solve(params,function(solveResult){
var polygonSymbol = new SimpleFillSymbol("solid",
new SimpleLineSymbol("solid", new Color([232,104,80]), 2),
new Color([232,104,80,0.25])
);
arrayUtils.forEach(solveResult.serviceAreaPolygons,function(serviceArea){
serviceArea.setSymbol(polygonSymbol);
map.graphics.add(serviceArea);
});
According to API ServiceAreaSolveResult https://developers.arcgis.com/javascript/3/jsapi/serviceareasolveresult-amd.html
ServiceAreaPolygon is already a graphic, and I can use its geometry in my query, but I donĀ“t know how I can get this geometry.
Thanks a lot!
you are correct! As mentined in document serviceAreaPolygons are already in esri graphic format.
Well, geometry is a property of the graphic. below is the way to access this.
In your case-
arrayUtils.forEach(solveResult.serviceAreaPolygons,function(serviceArea){
serviceArea.setSymbol(polygonSymbol);
var serviceAreaGeometry = serviceArea.geometry; // this is the geometry. you can use this geometry in your further query.
map.graphics.add(serviceArea);
});
Hoping this will help you.
Feel free to shoot your further queries.

JES - Jython - Drawing a line between points on an image

I am working on an assignment where I need to draw a line between points on a map. I built it up using if statements, but that limits how many times I can do something so want to use a loop.
The code I have so far is below, I can add the cities and draw a line, but it draws a line to itself rather than from a start point to the next point (and continue on)
Can anybody please help at all?
def level1():
cityXvalue = [45,95,182,207,256,312,328,350,374,400]
cityYvalue = [310,147,84,201,337,375,434,348,335,265]
# Display the map image
map = makePicture(getMediaPath("map.png"))
show(map)
number = 0
# Ask user to enter numbers of the cities they wish to visit
cities = requestInteger("Enter the number of the city you would like to visit")
# Draw a line between previously entered point and current one
while cities > number:
city = requestInteger("Please choose a city number")
addLine(map,cityXvalue[city],cityYvalue[city], cityXvalue[city], cityYvalue[city])
repaint(map)