Python script for creating envelope polygons for feature classes? - python

I'm trying to write a script that creates an envelope polygon feature for an existing feature class that contains multiple features. The output needs to be a single envelope polygon for all features combined instead of one polygon for each individual feature.
The output should consist of a new feature class with a single envelope polygon for the entire feature class, not a polygon for each feature. The output can be a shapefile or a geodatabase feature class. I also need to work with just the input feature class and/or the geometries of the input features. The script should also be able to work on any feature class (geometry type, coordinate system, etc.)
I've been using a shapefile that represents the Hawaii islands for testing.
This is my code so far:
import arcpy
arcpy.env.workspace = "C:/Shapefiles"
fc = "hawaii.shp"
ofc = "hawaii_env"
with arcpy.da.SearchCursor(fc, "SHAPE#") as cursor:
for row in cursor:
print(row[0].extent)
polygon = [arcpy.Polygon(arcpy.Array(
[arcpy.Point(row[0].extent.XMin, row[0].extent.YMin), arcpy.Point(row[0].extent.XMax, row[0].extent.YMin),
arcpy.Point(row[0].extent.XMax, row[0].extent.YMax), arcpy.Point(row[0].extent.XMin, row[0].extent.YMax)]))]
arcpy.CopyFeatures_management(polygon, ofc)
When I run the script, the shapefile it produces is just one polygon, but I don't believe it is working correctly. The one polygon is only covering one island of hawaii. I'm not sure of the exact output I should receive and what to look for in ArcGIS Pro.
Any code to try or advice would be very helpful, thank you

Related

Is there a way to create a nonlinear SVM who's decision bounday passes through two predefined points?

I am using Python to create nonlinear decision boundaries (DB) using nonlinear Support Vector Machines (SVMs).
My goal is to be able to specify a pair of coordinates and have the DB pass through these points. For example, in the below image, the two points where the DB is desired to pass through is shown by the orange and blue points. The ideal DB would look like the red line.
Currently, if I want the DB to pass through two points, I surround them in guide features, where the top-right are 1's and the bottom-left are zeros as is shown below:
This leads to a DB as is shown below.
My goal is to be able to force the DB to pass through two specific points without having to add the guide points. I am wondering if there is a way I can go about this?

Load Mesh from a glb file using trimesh

I am new to 3D geometry. I am trying to extract a mesh from a glb file using python library trimesh. I couldn't figure out the proper way of doing that.
My requirement is that I need a 3D mesh (as adjacency matrix) of an object so that I can apply non-euclidian convolutional operators on them.
Any suggestions on what I should be looking at?
You can use trimesh.load to load your glTF file. Note that the return type depends on the filetype of your model file. For glTF files it will return an instance of trimesh.Scene. The scene has all sorts of attributes like the camera, lights but also geometries. This is because glTF files can contain more that just model data. Each geometry is an instance of trimesh.Trimesh, which is the base class for geometries and has a edges_sparse property which represents the adjacency matrix of the model.
To put it all together:
scene = trimesh.load("some_file.glb")
geometries = list(scene.geometry.values())
geometry = geometries[0]
adjacency_matrix = geometry.edges_sparse
It's a bit tedious to figure this out using the documentation. I tend to look at the source code or turn on the debugger in my IDE:
trimesh.Scene: https://github.com/mikedh/trimesh/blob/master/trimesh/scene/scene.py
trimesh.Trimesh: https://github.com/mikedh/trimesh/blob/master/trimesh/base.py

Thiessen-like polygons out of pre-labeled points

I have a list of coordinate points that are already clustered. Each point is available to me as a row in a csv file, with one of the fields being the "zone id": the ID of the cluster to which a point belongs. I was wondering if there is a way, given the latitude, longitude and zone ID of each point, to draw polygons similar to Voronoi cells, such that:
each cluster is entirely contained within a polygon
each polygon contains points belonging to only one cluster
the union of the polygons is contiguous polygon that contains all the points. No holes: the polygons must border each other except at the edges. A fun extension would be to supply the "holes" (water bodies, for example) as part of the input.
I realise the problem is very abstract and could be very resource intensive, but I am curious to hear of any approaches. I am open to solutions using a variety or combination of tools, such as GIS software, Python, R, etc. I am also open to implementations that would be integrated into the clustering process.

How to draw polygons using Abaqus python script

I have (X,Y) coordinates of polygons as shown in the picture pores image. How can I import them to Abaqus and how to create a surface in a way that subtract the internal shapes (polygon1,poly2....) from the external shape (the frame (a rectangle)). Rectangle-poly1-poly2....
Try recording a macro. Manually create the model using Abaqus CAE. I assumed you're doing a 2-D model, so your geometry will probably be:
A solid rectangle.
2a. Planar cut on the rectangle created through a sketch.
2b. Alternatively, you can use the "create wire" feature to input your shape coordinates (right-click to read coordinates from a text file). Use merge scheme "Separate wire". Then, use the "Partition" tool to partition the holes, and then use "Geometry Edit" to remove the undesired faces.
Anyways, the macro recorder will help prototype the code that you will need to generate. Once you do that, you're going to need to do typical Python file open/read operations to read the input coordinates and develop the program to generate the model and mesh. Or, you can extruciatingly generate your model manually using the method I outlined above. There's a lot of ways to skin this chicken.

Query Attributes - Model Builder ArcGIS

I'm trying to build a Model that selects points (stores) from a point shapefile that are within a polygon shapefile (block groups) and then assigns the the name attribute (Block Group ID) of that specific polygon to a new field in the points shapefile. Since I have a lot of points and a lot of polygons, I have made the process iterative meaning that the model will cycle through the total list of polygons and find any points located within a certain polygon to assign the name to the point shapefile's new field.
So far I have been able to select the a polygon and select the points within that polygon. I'm trying to find a way to write the name of that polygon to the new field in the points associated with it.
This is a screenshot of what I have so far:
http://i67.tinypic.com/qqv0y9.jpg
An alternative approach to consider is doing a Spatial Join.
Spatial Join (Analysis)
http://resources.arcgis.com/en/help/main/10.2/index.html#//00080000000q000000
You could also perform a Join based on Location
http://resources.arcgis.com/en/help/main/10.2/index.html#//005s0000002n000000

Categories