This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Export Shapefile of Network using WaterObjects

I have a WaterObjects application and would like to export the calculated water quality results to a shapefile of my pipe network.  I can do this in WaterCAD by selecting Report->Element Tables -> Pipe, selecting the properties I want to export, and clicking on the export button and selecting ESRI Shapefile as my export format.  Would anybody know if this can be accomplished using WaterObjects?  I don't necessarily need to see the flex table that gets generated, but if it was necessary to generate the flex table in order to export the shapefile then I could deal with that.

  • Hi Bruce, by searching for "Waterobjects shapefile" in the search bar, I came across this similar discussion from a few years ago:

    communities.bentley.com/.../89113

    This points to a sample we have available on communities that has code that may help you with your shapefile export.


    Regards,

    Jesse Dringoli
    Technical Support Manager, OpenFlows
    Bentley Communities Site Administrator
    Bentley Systems, Inc.

  • Thanks very much for finding this prior post on creating a shapefile. The bits of code in the description were tremendously helpful and I think I know now what needs to be done. Here's the first part of my code.

    Dim dbFields(3) As DBFFieldInfo
    dbFields(0) = New DBFFieldInfo("MonYr", DBFFieldType.String)
    dbFields(0) = New DBFFieldInfo("Id", DBFFieldType.String)
    dbFields(1) = New DBFFieldInfo("conc", DBFFieldType.Double)
    dbFields(2) = New DBFFieldInfo("StrtNd", DBFFieldType.String)
    dbFields(3) = New DBFFieldInfo("EndNd", DBFFieldType.String)
    Dim shpWriter As ShapefileDataSourceWriter = New ShapefileDataSourceWriter()
    shpWriter.CreateDataFile(pathShpFle, dbFields, True, ShapeType.Polyline)

    When I reach the CreateDataFile step in debug mode, it throws a DllNotFoundException with the message "Unable to load DLL 'c4dll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)". I see from a note in the WaterObjects.Net Samples Guide, that c4dll.dll is a file that comes with WaterGEMS. Since I am using WaterCAD, I don't have this file. Is there any way around this? Can I get the c4dll.dll file withoug purchasing a WaterGEMS license?
  • Bruce, I'm glad to hear that post helped.

    What version of WaterCAD are you using? Check the number under Help > About. The latest is SELECTseries 5, 08.11.05.61.

    I checked a copy of WaterCAD SELECTseries 4 and SELECTseries 5 and see that the file c4dll.dll does exist. There appears to be a "c4dll.dll" in the root installation folder (default: C:\Program Files (x86)\Bentley\WaterCAD) and a "C4DLL.DLL in the \x64 subfolder. The former contains the 32-bit version of WaterCAD and the latter contains the 64-bit version. These two files appear to be the exact same copy as the one provided with WaterGEMS.

    If this doesn't help, can you provide some further details, such as a snipit of code and the location you are placing the files?

    There are two options for sharing your model files on Communities. If you would like the files to be visible to other members, compress the files into a zip file and upload them as an attachment using the ‘Advanced Reply editor’ before posting. If your data is confidential, you can follow the instructions in the link below to send it to us via Bentley Sharefile. Files uploaded to Sharefile can only be viewed by Bentley.

    communities.bentley.com/.../7079.be-communities-secure-file-upload


    Regards,

    Jesse Dringoli
    Technical Support Manager, OpenFlows
    Bentley Communities Site Administrator
    Bentley Systems, Inc.

    Answer Verified By: Bruce Jacobs 

  • As you said, the dll was in the WaterCAD folder. I didn't realize that I would need to copy it to the same folder as my executable. Everything seems to be working now. Thanks for your help.
  • shapefile.zipJesse,

    I seem to be almost there.  The shapefile plots fine, however when I open the dbf file all of the fields in every record is Null.  I'm in the advanced reply editor and I think I've posted the shapefile as shapefile.zip.   I'll put the relevant code here to see if you see something obviously wrong in what I've done.

    ' Here's where I create the ShapefileDataSourceWriter

                   Dim dbFields(4) As DBFFieldInfo

                   dbFields(0) = New DBFFieldInfo("MonYr", DBFFieldType.String)

                   dbFields(1) = New DBFFieldInfo("Id", DBFFieldType.String)

                   dbFields(2) = New DBFFieldInfo("conc", DBFFieldType.Double)

                   dbFields(3) = New DBFFieldInfo("StrtNd", DBFFieldType.String)

                   dbFields(4) = New DBFFieldInfo("EndNd", DBFFieldType.String)

                   Dim shpWriter As ShapefileDataSourceWriter = New ShapefileDataSourceWriter()

                   shpWriter.CreateDataFile(pathShpFle, dbFields, True, ShapeType.Polyline)

    ' I do a bunch of other stuff here including running WaterCAD

    .

    .

    .

    .

    ' Here's where I save results to the shapefile

                           For Each aintElementId As Integer In acollection

                               Dim fldIsActive As IField = junctionElementManager.Element(aintElementId).SupportedFields().Item(nIsActiveFieldIndex) ' 53 = IsActive

                               If fldIsActive.GetValue(aintElementId) Then

                                   Dim v As Double = CType(f, IResultTimeVariantField).GetValue(aintElementId, id, aiTimeStepCount - 1)

                                   Dim sLabel As String = junctionElementManager.Element(aintElementId).Label

                                   Dim flds4 As Haestad.Support.Support.FieldCollection = junctionElementManager.Element(aintElementId).SupportedFields()

                                   Dim strtNode As String = junctionElementManager.Element(aintElementId).SupportedFields().Item(54).GetValue(aintElementId)

                                   Dim endNode As String = junctionElementManager.Element(aintElementId).SupportedFields().Item(55).GetValue(aintElementId)

                                   Dim strtElem As IModelingElement = junctionElementManager.Element(strtNode)

                                   Dim flds5 As Haestad.Support.Support.FieldCollection = strtElem.SupportedFields()

                                   Dim x0 As Double = 0

                                   Dim y0 As Double = 0

                                   Dim nField As Integer = 0

                                   For Each x As IField In flds5

                                       If (x.Name.Contains("XCoordinate")) Then

                                           x0 = strtElem.SupportedFields().Item(nField).GetValue(strtNode)

                                           y0 = strtElem.SupportedFields().Item(nField + 1).GetValue(strtNode)

                                           Exit For

                                       End If

                                       nField += 1

                                   Next

                                   Dim endElem As IModelingElement = junctionElementManager.Element(endNode)

                                   Dim flds6 As Haestad.Support.Support.FieldCollection = endElem.SupportedFields()

                                   nField = 0

                                   Dim x1 As Double = 0

                                   Dim y1 As Double = 0

                                   For Each x As IField In flds6

                                       If (x.Name.Contains("XCoordinate")) Then

                                           x1 = endElem.SupportedFields().Item(nField).GetValue(endNode)

                                           y1 = endElem.SupportedFields().Item(nField + 1).GetValue(endNode)

                                           Exit For

                                       End If

                                       nField += 1

                                   Next

                                   shpWriter.AddRecordBegin()

                                   shpWriter.WriteFieldData(sMonthYr, "MonYr")

                                   shpWriter.WriteFieldData(sLabel, "Id")

                                   shpWriter.WriteFieldData(v, "conc")

                                   shpWriter.WriteFieldData(strtElem.Label, "StrtNd")

                                   shpWriter.WriteFieldData(endElem.Label, "EndNd")

                                   Dim geoPt0 As GeometryPoint = New GeometryPoint(x0, y0)

                                   Dim geoPt1 As GeometryPoint = New GeometryPoint(x1, y1)

                                   Dim ln() As GeometryPoint = {geoPt0, geoPt1}

                                   shpWriter.WritePolylineGeometry(ln)

                                   shpWriter.AddRecordEnd()

                               End If

                           Next