Page 1 of 1

import coordinates including point number, height and code

Posted: Mon Jul 13, 2020 6:09 pm
by tomek
Hello.
This topic appears more often here (topic for land surveyors), but I did not find a solution. I'm trying use QCAD instead of Bentley products. I need import a list of measured points (txt file) in the format "point number", "Y", "X", "H" and "code". QCAD is 2D sw, so number, height and code can be displayed only as text (number to the left of the point, height at the top right, code at the bottom right). And optimally so that the number, point, height and code are in a separate layer. I can import points using the link https://qcad.org/en/tutorial-using-a-li ... oordinates, but that's not enough for my purposes.
Please help with the solution.
Thank you.

Re: import coordinates including point number, height and code

Posted: Tue Jul 14, 2020 12:40 am
by CVH
Scripting is the way I think.
I offered it twice but left hanging when I asked if there was any kind of normalisation.
This time 5 things, mostly text, no blocks but different layers.

Its not that hard to put something in the drawing with a script.
Reading the source, casting this or that way and hardening for errors is complexer.

And now my time is limited ... :wink:

Regards,
CVH

Re: import coordinates including point number, height and code

Posted: Tue Jul 14, 2020 4:52 am
by tomek
Hello,
thank you for answer.
There is no standard for displaying points. The habits of surveyors will be determined by their practice and software. Blocks will be preferred by AutoCAD users, layers by Bentley product users. In principle, it is generally a possibility to import, together with the point, additional information according to which the drawing is then realized. The standards are then except for the types of lines and cells, but they will be different for each country. As a user of Bentley products, I prefer layers due to the possibility of different views during processing and printing. In general, a simple import from a txt file (csv file) would be enough to display the required ID, point, H, code. In my case, this survey of points into MicroStation uses an extension for surveyors, which can do much more (quadrant selection, number of decimal places, attributes for layers, bidirectional coordinate transfer, the ability to transfer one, more or all points, etc.) but I understand that this is well beyond the scope of the simple import question. Here I am generally interested in the possibility of extended import from the input file.
Thank you for your time.

Re: import coordinates including point number, height and code

Posted: Wed Jul 15, 2020 5:53 pm
by tomek
OK,
scripting is the way. I managed to solve my problem for one point. It's a good start, now the hard part - how to do it from input file.
The following set of commands creates layers, creates a point, and the desired text descriptions.
Tomek.

addLayer("point", "white", "CONTINUOUS", RLineweight.Weight025);
addLayer("number", "white", "CONTINUOUS", RLineweight.Weight025);
addLayer("height", "yellow", "CONTINUOUS", RLineweight.Weight025);
addLayer("code", "blue", "CONTINUOUS", RLineweight.Weight025);

setCurrentLayer("number"); addPoint (0, 0);

setCurrentLayer("number"); addSimpleText("500", 0,0, 0.15, 0, "Standard", RS.VAlignMiddle, RS.HAlignRight, false, false);
setCurrentLayer("height"); addSimpleText("507,300", 0,0, 0.10, 0, "Standard", RS.VAlignBase, RS.HAlignLeft, false, false);
setCurrentLayer("code"); addSimpleText("CODE", 0,0, 0.10, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false);

Re: import coordinates including point number, height and code

Posted: Wed Jul 15, 2020 6:16 pm
by CVH
The basics for reading a text source can be found here:
ImportPoints.js :P
the script that sits under Menu ... Misc ... Import/Export ... Import Points

In a standard installation only compiled present.
I have a copy of the sources from github at hand.
https://github.com/qcad/qcad

With the layer and the text thing you are on the right track. :wink:

Regards,
CVH

Re: import coordinates including point number, height and code

Posted: Wed Jul 29, 2020 8:47 pm
by tomek
I was busy for a long time. However, below is the code for the required function (for other surveyors). GUI and other options (quadrant selection, attributes, coordinate order) would be desirable, but the basic functionality is solved. Thanks for the help.

include("scripts/EAction.js");
include("scripts/simple.js");

function ImportPoints(guiAction) {
EAction.call(this, guiAction);
}

ImportPoints.prototype = new EAction();

ImportPoints.prototype.beginEvent = function() {
EAction.prototype.beginEvent.call(this);

var appWin = EAction.getMainWindow();
var initialPath = QDir.homePath();
var filterAll = qsTr("All Files") + " (*)";
var fileDialog = new QFileDialog(appWin, qsTr("Import Points"), initialPath, "");
fileDialog.setNameFilters([ filterAll ]);
fileDialog.selectNameFilter(filterAll);
fileDialog.setOption(QFileDialog.DontUseNativeDialog, getDontUseNativeDialog());
if (!isNull(QFileDialog.DontUseCustomDirectoryIcons)) {
fileDialog.setOption(QFileDialog.DontUseCustomDirectoryIcons, true);
}
fileDialog.fileMode = QFileDialog.ExistingFiles;
if (!fileDialog.exec()) {
fileDialog.destroy();
EAction.activateMainWindow();
this.terminate();
return;
}

var files = fileDialog.selectedFiles();
if (files.length===0) {
fileDialog.destroy();
EAction.activateMainWindow();
this.terminate();
return;
}

fileDialog.destroy();
EAction.activateMainWindow();

var fileName = files[0];

var document = this.getDocument();
var di = this.getDocumentInterface();

var file = new QFile(fileName);
var flags = new QIODevice.OpenMode(QIODevice.ReadOnly | QIODevice.Text);
if (!file.open(flags)) {
this.terminate();
return;
}

var ts = new QTextStream(file);
ts.setCodec("UTF-8");
var line;
var coordinates;

addLayer ("point", "white", "CONTINUOUS", RLineweight.Weight025);
addLayer ("number", "white", "CONTINUOUS", RLineweight.Weight025);
addLayer ("height", "yellow", "CONTINUOUS", RLineweight.Weight025);
addLayer ("code", "blue", "CONTINUOUS", RLineweight.Weight025);


var operation = new RAddObjectsOperation();
do {
line = ts.readLine();
coordinates = line.split(',');
if (coordinates.length!==5) {
// skip line with invalid point format
continue;
}
var v = new RVector(parseFloat(coordinates[1]), parseFloat(coordinates[2]));
point = new RPointEntity(document, new RPointData(v));
setCurrentLayer ("number"); addSimpleText(coordinates[0], new RVector(parseFloat(coordinates[1]), parseFloat(coordinates[2])), 0.15, 0, "Standard", RS.VAlignMiddle, RS.HAlignRight, false, false);
setCurrentLayer ("height"); addSimpleText(coordinates[3], new RVector(parseFloat(coordinates[1]), parseFloat(coordinates[2])), 0.10, 0, "Standard", RS.VAlignBase, RS.HAlignLeft, false, false);
setCurrentLayer ("code"); addSimpleText(coordinates[4], new RVector(parseFloat(coordinates[1]), parseFloat(coordinates[2])), 0.10, 0, "Standard", RS.VAlignTop, RS.HAlignLeft, false, false);
setCurrentLayer ("point"); operation.addObject(point);

} while(!ts.atEnd());

file.close();

di.applyOperation(operation);

this.terminate();
};

/**
* Adds a menu for this action to Examples/Math Examples/ImportPoints.
*/
ImportPoints.init = function(basePath) {
var action = new RGuiAction(qsTr("&Import Points"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/ImportPoints.js");
action.setGroupSortOrder(52100);
action.setSortOrder(100);
action.setWidgetNames(["MiscIOMenu", "MiscIOToolBar", "MiscIOToolsPanel"]);
};

Re: import coordinates including point number, height and code

Posted: Thu Jul 30, 2020 7:47 am
by CVH
Great,
two things:
A) On this forum one can use a code plane (in editmode, above, icon 5)
(And you can edit your previous posts :wink: )

B) You should at least choose a unique script and function name.
Why not ImportSurveyorPoints?

For this you change any text 'ImportPoints' in the new name.
Next adapt the init section:
ImportPoints is 52100/100, MOL import 52100/200
The choise is yours 150 or 300
new RGuiAction: Adapt textual, the '&' is for the key-in navigator
Extra's: (but none is really required)

Code: Select all

action.setRequiresSelection(false);
action.setIcon(basePath + "/ImportPoints.svg");
action.setDefaultShortcut(new QKeySequence("Your sequence"));     // Look up if free in APP.Prefs 
action.setDefaultCommands(["Long command", "Shortcommand"]);    // An Array
var tip = qsTr("What your function does");
action.setStatusTip(tip + " " + qsTr("somewhat more in specific"));    // Overtakes and displays left in the Status Bar
action.setToolTip(tip);    // Displays aside Toolbars
If you use it fairly often or when testing I add "MainToolsPanel" to the list setWidgetNames.

Finally, put your script under a subfolder of folder 'MiscIO' with the same name as the script except the extention.

Keep us posted.
Regards,
CVH

Re: import coordinates including point number, height and code

Posted: Thu Jul 30, 2020 8:43 am
by CVH
Now I come to think of it ...
I don't see startTransaction(...), nor endTransaction()
It's faster as a group and meanwhile it collects your castings in one operation one can undo in one go.
See: simple_transaction.js

The 'simple' form of operation.addObject(point); is addpoint(v);

You can reuse var v for any new RVector(parseFloat(coordinates[1]), parseFloat(coordinates[2])) that follows.

Andrew has not the habbit of putting more commands on one script-line.

Regards,
CVH

Re: import coordinates including point number, height and code

Posted: Thu Jul 30, 2020 9:18 am
by Husky
CVH wrote:
Thu Jul 30, 2020 7:47 am
(And you can edit your previous posts :wink: )
What we don't appreciate in this forum!
Changing previous post content is extremely confusing for everybody who reads a thread and tries to understand how it came to a final conclusion.

Re: import coordinates including point number, height and code

Posted: Thu Jul 30, 2020 9:30 am
by CVH
In this case it looks better in a code plane.
The content remains the same.
CVH

Re: import coordinates including point number, height and code

Posted: Sun Mar 07, 2021 11:13 pm
by WI-RLS
I downloaded QCAD yesterday, so I too am a newbee, and am also interested in "Survey" Points Which are very different than regular CAD points, unfortunately we all call them by the same name "points". 20 years ago I reverse engineered the "survey" points from a major CAD program. What I think I remember was that they were actually blocks. One was a block with the point (x) with the insertion point extracted and containing the yxz (northing, easting, elevation) info. inserted into that block were three text blocks, one extracting the unique identifier (point number/name), next the extracted elevation number, next the extracted description/code, all four on separate layers. I am not a programmer, but let me know if any of this seems helfull, and I can elaborate much more.
Thank you,
WI-RLS

Re: import coordinates including point number, height and code

Posted: Fri Jun 04, 2021 9:19 am
by andrew
QCAD 3.26.4 comes with a new tool to import point data with labels from CSV:
https://qcad.org/en/tutorial-importing- ... s-from-csv