X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 12 Jan 2017 08:52 AM by  anon
How delete a specific record from an ESRI Shapefile in IDL
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
12 Jan 2017 08:52 AM
    Hello, i need to delete a specific feature from a shapefile using IDL but i do not find any usefull tool or function. That is my simplified code: myshape = OBJ_NEW('IDLffShape', file); Get the number of entities so we can parse through them myshape->GetProperty, N_ENTITIES=num_ent; Parsing through the entities FOR x=0, (num_ent-1) DO begin ; Get the Attributes for entity x attr = myshape->GetAttributes(x) IF attr.ATTRIBUTE_0 EQ 'Roi_Test_v2 [RECORD=2]' THEN BEGIN IF (Stats.Mean LT 7000) THEN myshape->DestroyEntity, ent OBJ_DESTROY, shape ENDIF ENDFOR The myshape->DestroyEntity does not work. I obtains the following message: Only one class has training samples within the valid image area. Thank you for any feedback.

    Deleted User



    Basic Member


    Posts:143
    Basic Member


    --
    12 Jan 2017 01:07 PM
    What are yo udoing int he code that says, "". I am skeptical that this error is occurring when you call "myshape->DestroyEntity, ent". I think this error typically occurs when running a classification using ENVI. I wonder if that might be the cause of your issue?

    Deleted User



    New Member


    Posts:
    New Member


    --
    13 Jan 2017 02:09 AM
    The code that extract statistics consists on these steps: Create a new shapefile with only the selected entity with its attributes Add the .prj file copying it from the original Open the new shapefile with IDLffShape and GetAttribute Extact the records Open the new shapefile with OpenVector Create a new Roi with EnviRoi Add the record using AddVectorRecords, myvector, record Save the roi as xml file Open the new roi xml file Use the EnviRoiMaskRaster(my_raster, roi_xml) command Use ENVIRasterStatistics (masked_raster) to obtain the mean as Stats.Mean Now i tryed to execute the command: IF (Stats.Mean LT 7000) THEN myshape->DestroyEntity, ent Then i tryed to do another thing: create a roi.xml from the original shapefile i want modified to delete the corresponding VectorRecords using the code: IF (Stats.Mean LT 7000) THEN rois_xml.ClearVectorRecords, myvector where rois_xml is a roi.xml file corresponding to the first shapefile opened before the FOR cicle and named myshape (see previous post). This code does not exit with an error but does nothing and does not modify the rois_xml file. If you want to see the full code ask me. But my need is simple: i want cicle inside a vector of polygons, compute the mean over a raster for each polygon, apply a condition (mean less then 7000), delete the corresponding entity from the shapefile, save the new shapefile. Using vector utilities or roi utilities or both it's the same thing for me.
    You are not authorized to post a reply.