Jest Posted March 21 Posted March 21 I have a large SHP file attached to my drawing, and sometimes need to convert some items to closed polylines, and also get data from "Feature Properties" table. The only procedure I know is...start MAPExtractFeatureGeometry command to get Mpolygon and then explode it to get polyline. Unfortunately "Feature Properties" are lost with Mpolygon already. Is there a way to keep those data and write it to polyline's OD table?.... a Lisp maybe? Kind regards Quote
Danielm103 Posted March 21 Posted March 21 (edited) Python’s geopandas can read shp files. Not sure if your program can run the wrappers I’m working on, or the additional data you need. Maybe a source of inspiration import traceback from pyrx_imp import Rx from pyrx_imp import Ge from pyrx_imp import Gi from pyrx_imp import Db from pyrx_imp import Ap from pyrx_imp import Ed from pyrx_imp import Gs import geopandas def makePline(pnts, model, color): pline = Db.Polyline(pnts) pline.setColorIndex(color) model.appendAcDbEntity(pline) def PyRxCmd_doit(): try: db = Db.curDb() model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) gdf = geopandas.read_file("E:/townssurvey_shp/TOWNSSURVEY_ARC_GENCOAST.shp") #do MultiPolygon first gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon'] for mp in list(gdf0.geometry): for p in mp.geoms: makePline(list(p.exterior.coords), model, 1) gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon'] for p in gdf1.geometry: makePline(list(p.exterior.coords), model, 2) gdf2 = gdf.loc[gdf.geometry.geometry.type=='LineString'] for p in gdf2.geometry: makePline(list(p.coords), model, 3) print(gdf) except Exception as err: traceback.print_exception(err) Edited March 21 by Danielm103 Quote
tombu Posted March 26 Posted March 26 To Import SHP Files Look at step 7. By default, polygons are imported as polygon objects. To import them as closed polylines, select Import Polygons As Closed Polylines. Quote
Jest Posted March 26 Author Posted March 26 45 minutes ago, tombu said: To Import SHP Files Look at step 7. By default, polygons are imported as polygon objects. To import them as closed polylines, select Import Polygons As Closed Polylines. Yes I know that....but my shp file is connected, not imported (Task Pane - Display manger - Connect to Data - Add Shp Connection.....) Quote
Jest Posted March 26 Author Posted March 26 On 3/21/2024 at 1:18 PM, Danielm103 said: Python’s geopandas can read shp files. Not sure if your program can run the wrappers I’m working on, or the additional data you need. Maybe a source of inspiration import traceback from pyrx_imp import Rx from pyrx_imp import Ge from pyrx_imp import Gi from pyrx_imp import Db from pyrx_imp import Ap from pyrx_imp import Ed from pyrx_imp import Gs import geopandas def makePline(pnts, model, color): pline = Db.Polyline(pnts) pline.setColorIndex(color) model.appendAcDbEntity(pline) def PyRxCmd_doit(): try: db = Db.curDb() model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) gdf = geopandas.read_file("E:/townssurvey_shp/TOWNSSURVEY_ARC_GENCOAST.shp") #do MultiPolygon first gdf0 = gdf.loc[gdf.geometry.geometry.type=='MultiPolygon'] for mp in list(gdf0.geometry): for p in mp.geoms: makePline(list(p.exterior.coords), model, 1) gdf1 = gdf.loc[gdf.geometry.geometry.type=='Polygon'] for p in gdf1.geometry: makePline(list(p.exterior.coords), model, 2) gdf2 = gdf.loc[gdf.geometry.geometry.type=='LineString'] for p in gdf2.geometry: makePline(list(p.coords), model, 3) print(gdf) except Exception as err: traceback.print_exception(err) Thank you for help, but I have no Idea how to use it. I know something about Lisp routines, but not about this kind....I am not expert, just average user. Kind regards 1 Quote
tombu Posted March 27 Posted March 27 15 hours ago, Jest said: Yes I know that....but my shp file is connected, not imported (Task Pane - Display manger - Connect to Data - Add Shp Connection.....) Workflow I used for many years was having a reference drawing with shp files connected with labels as a quick reference. When I needed polylines with "Feature Data" I'd draw a rectangle in my reference drawing around the area I needed, copy it into a new drawing and import them using that rectangle as the area. If you select one of those polylines you can see the "Feature Data" in the Properties Palette but to use the "Feature Data" beyond that requires code. I always used lisp for that. As I understand Python can be used in both Map 3D and GIS software now but wasn't available years ago when I created my workflow. I used the attached lisp for everything from labeling contours, street names and property info to opening online property records. Unfortunately to access "Feature Data" requires specific GIS information about that data. Our GIS folk seemed to modify how it was stored and named every other year requiring me to modify the code each time. Which means nobody else's code will work for your shapefiles. For someone starting fresh on doing this Python would probably be better to learn. ContourAnnotate.lsp Quote
BIGAL Posted March 28 Posted March 28 Just a quick comment (ade_odgettables ent) look up help about using ade but you have to know the key names for it to work as suggested by Tombu. Just google "ade_odgettables autocad lsp" lots of help. Quote
Jest Posted March 28 Author Posted March 28 In case to use MAPIMPORT option, I wish to have s Lisp routine, to run this procedure with one click, because I must do this often and with files on different locations. Can somebody help and write it? For instance.....file location c:\Documents\Temp\Test.shp I want to import Polygons as Closed Polylines and must contains Object Data. I've tried to record a macro, but it doesn't work well (just beginning and then I have to make all other manually. It couldn't remember neither file location). I prefer Lisps. Regards Quote
tombu Posted March 28 Posted March 28 The data you want is attached to entities in tables and fields. The names and amounts of those tables and fields vary greatly from one entity to another as well as one organization to another as you can see in the bottom of the Properties Palette when an object with object data is selected. That's why your code has to be unique to your organization's GIS data and no code from someone who isn't in your organization could ever work for you. Here's a couple old help links for Map lisp with an older help file you can download and open with a double-click. AutoCAD Map 3D 2009 AutoLISP Reference Object Data Functions Hope that helps, good luck! acmaplisp.chm Quote
jesse628wallick Posted March 29 Posted March 29 Converting a Map Feature from an attached SHP file to a closed polyline while retaining the Object Data in AutoCAD can be a bit tricky, but it’s possible. Use the MAPIMPORT command to import the SHP file into your drawing. During the import process, select the option to create an Object Data table for the attributes. Once imported, use the MAPEXPORT command to export the data to an SDF file. Then, use the MAPIMPORT command again to import the SDF file back into AutoCAD. This time, the features should come in as polylines with the Object Data attached. Additionally, you might consider using a LISP routine or a Python script to automate this process, especially if you’re dealing with a large number of features. The Python geopandas library, for example, can read SHP files and be used to script the conversion process. Remember, the exact steps may vary depending on your version of AutoCAD and the specific details of your SHP file and Object Data. It’s always a good idea to back up your data before converting. Quote
Jest Posted March 29 Author Posted March 29 On 3/28/2024 at 1:36 PM, Jest said: In case to use MAPIMPORT option, I wish to have s Lisp routine, to run this procedure with one click, because I must do this often and with files on different locations. Can somebody help and write it? For instance.....file location c:\Documents\Temp\Test.shp I want to import Polygons as Closed Polylines and must contains Object Data. I've tried to record a macro, but it doesn't work well (just beginning and then I have to make all other manually. It couldn't remember neither file location). I prefer Lisps. Regards It is OK now....I have found the solution. Thanks to "hippe013" and his example on (https://forums.autodesk.com/t5/civil-3d-customization/i-want-lisp-to-use-mapimport-command-with-file-path-thanks-in/td-p/11887807) His lisp based on KML file, without Object Data as a result: (defun c:MyMapImport() (setvar "FILEDIA" 0) (command "-mapImport" "OGCKML" "C:\\Users\\MyUserName\\Desktop\\MyMap.kml" "No" "Layer" "All" "Coordinate" "LL84" "Proceed" "Import" "Yes" "Proceed") (setvar "FILEDIA" 1) (princ) ) ....I modified a Lisp to my needs...... SHP file, Object Data included and without coordinate system settings... main line looks like this. (command "-mapImport" "SHP" "C:\\Users\\MyUserName\\Desktop\\Test.shp" "No" "Layer" "All" "Data" "C" "Proceed" "Import" "Yes" "Proceed") Kind regards Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.