Categories
PHP

Конвертиране от DINI21 към TXT или XML

Преобразуване на файлове от дигитален нивелир DINI21 към XML или TXT файл

Базов код на PHP:

<?php
$submit_button = "Преобразуване";
$upload_dir = "./upload";
$output_file = "";

if (
    isset($_POST["submit"], $_POST["format"]) &&
    $_POST["submit"] === $submit_button
) {
    if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
        $old_filename = htmlentities(
            $_FILES["file"]["name"],
            ENT_QUOTES,
            "UTF-8"
        );
        $new_filename = sprintf(
            "%s_%s.txt",
            md5($_FILES["file"]["name"]),
            time()
        );
        if (
            move_uploaded_file(
                $_FILES["file"]["tmp_name"],
                $upload_dir . DIRECTORY_SEPARATOR . $new_filename
            )
        ) {
            $input_file = file_get_contents(
                $upload_dir . DIRECTORY_SEPARATOR . $new_filename
            );
            unlink($upload_dir . DIRECTORY_SEPARATOR . $new_filename);
            $file_formats = [
                "TXT" => "txt",
                "XML" => "xml",
            ];
            $file_format = isset($file_formats[$_POST["format"]])
                ? $file_formats[$_POST["format"]]
                : $file_formats["TXT"];
            if (
                preg_match_all(
                    "/(\d+\s+Start-Line\s+BF\s+\d+)(.*?)(\d+\s+End-Line\s+\d+)/ism",
                    $input_file,
                    $matches
                )
            ) {
                if ($file_format == "xml") {
                    $output_file = "";
                    $output_file .= "";
                    $output_file .= "1";
                    $output_file .= "";
                    $output_file .= "";
                }
                foreach ($matches[0] as $line) {
                    $line = explode("\n", $line);
                    $back_benchmark = null;
                    $forward_benchmark = null;
                    $elevation = null;
                    $length = null;
                    for ($i = 1; $i < count($line) - 3; $i++) {
                        if ($i % 3 == 0) {
                            $rb = explode(
                                " ",
                                preg_replace(
                                    "/\s\s+/",
                                    " ",
                                    trim($line[$i - 1])
                                )
                            );
                            $rf = explode(
                                " ",
                                preg_replace("/\s\s+/", " ", trim($line[$i]))
                            );
                            if ($rb[1] != "X" && $rf[1] == "X") {
                                $back_benchmark = $rb[1];
                                $elevation += $rb[5] - $rf[5];
                                $length += $rb[7] + $rf[7];
                                continue;
                            } elseif ($rb[1] == "X" && $rf[1] == "X") {
                                $elevation += $rb[5] - $rf[5];
                                $length += $rb[7] + $rf[7];
                                continue;
                            } elseif ($rb[1] == "X" && $rf[1] != "X") {
                                $forward_benchmark = $rf[1];
                                $elevation += $rb[5] - $rf[5];
                                $length += $rb[7] + $rf[7];
                            } else {
                                $back_benchmark = $rb[1];
                                $forward_benchmark = $rf[1];
                                $elevation = $rb[5] - $rf[5];
                                $length = $rb[7] + $rf[7];
                            }
                            if ($file_format == "xml") {
                                $output_file .= "";
                                $output_file .= "" . $back_benchmark . "";
                                $output_file .= "" . $forward_benchmark . "";
                                $output_file .= "" . $elevation . "";
                                $output_file .= "" . $length . "";
                                $output_file .= "0";
                                $output_file .= "";
                                $output_file .= "\n";
                            } else {
                                $output_file .= sprintf(
                                    "%s %s %1.4f %1.2f 0\n",
                                    $back_benchmark,
                                    $forward_benchmark,
                                    $elevation,
                                    $length
                                );
                            }
                            $elevation = 0;
                            $length = 0;
                        }
                    }
                }
                if ($file_format == "xml") {
                    $output_file .= "";
                    $output_file .= "";
                }
            }
        } else {
            echo "Възникнала е грешка при качването на Файла " .
                $old_filename .
                "";
        }
    } else {
        echo "Няма избран файл за качване!";
    }
}
Categories
VB.NET

Четене на файл във Visual Basic

Четене на файлове във VB.NET чрез използване на StreamReader класа.

Dim fileName As String = "файл.txt"
Using reader As StreamReader = New StreamReader(fileName, Encoding.UTF8)
While Not reader.EndOfStream
'ред
Dim line() As String = Split(reader.ReadLine, " ")
'действие
End While
End Using
view raw File.vb hosted with ❤ by GitHub
Categories
PHP

PHP клас за сваляне на видео файлове от Vbox7

Описание:

Това е работещ клас на PHP за сваляне на видео файлове от VBOX7.

Използва CURL за изпращане на POST REQUEST, който връща директния URL адрес към видео файла.

Този клас може да се ползва и модифицира без никакви ограничения.

Автор: GNNMobile.eu

Код:

<?php
class VBox7 {
private $vid = null;
private $url = null;
public function setVideo($vid){
$this->vid = $vid;
}
public function execute(){
if (isset($this->vid)) {
$url = 'http://vbox7.com/play/magare.do';
$body = sprintf('vid=%s', $this->vid);
$c = curl_init($url);curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $body);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($c);
curl_close($c);
if (preg_match('@(http:\/\/media[0-9]+\.vbox7\.com\/s\/[a-z0-9]{2}\/[a-z0-9]+\.)(flv|mp4)@ui', $page, $matches)) {
$this->url = $matches[0];
return true;
}
}
return false;
}
public function getVideo(){
return $this->url;
}
}
view raw VBox7.php hosted with ❤ by GitHub

Пример:

$vbox = new Vbox7;
$vbox->setVideo($_POST['video']);

if ($vbox->execute()) { 
    echo '<a href="'.$vbox->getVideo().'">свали видео файл</a>'; 
}
Categories
VB.NET

Отваряне на ESRI Shape (SHP) файлове

Проект на VB.NET за отваряне на ESRI Shape (*.shp) файлове.

Използва е библиотеката SharpMap.

Функционалност:

  • Отваряне на файл;
  • Показване/скриване на слой;
  • Приближаване в пълен обхват;
  • Местене.

Този код може да се използва и модифицира без никакви ограничения.

Автор: GNNMobile.eu

Imports SharpMap
Imports System.IO
Imports System.Drawing
Public Class Main
Private isNewLayer As Boolean = False
Private Sub formLoad() Handles MyBase.Load
Try
btnZoomToExtents.Enabled = False
btnPan.Enabled = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub zoomToExtents() Handles btnZoomToExtents.Click
Try
With MC
.Map.ZoomToExtents()
.Refresh()
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub pan() Handles btnPan.Click
Try
MC.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub open() Handles btnOpen.Click
Try
With OpenFD
.InitialDirectory = Directory.GetCurrentDirectory
.Title = "Отваряне на Shp файл:"
.Filter = "Shp файлове (*.shp)|*.shp"
End With
If OpenFD.ShowDialog = DialogResult.OK Then
addLayer(OpenFD.SafeFileName, OpenFD.FileName)
isNewLayer = True
Layers.Items.Add(OpenFD.SafeFileName, True)
btnZoomToExtents.Enabled = True
btnPan.Enabled = True
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub changeLayerVisibility() Handles Layers.ItemCheck
Try
If isNewLayer = False Then
Dim layer As SharpMap.Layers.ILayer = MC.Map.Layers(Layers.SelectedItem)
layer.Enabled = If(Layers.GetItemCheckState(Layers.SelectedIndex) = 0, True, False)
MC.Refresh()
Else
isNewLayer = False
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub addLayer(ByVal layerName As String, ByVal file As String)
Dim vectorLayer = New SharpMap.Layers.VectorLayer(layerName)
vectorLayer.DataSource = New SharpMap.Data.Providers.ShapeFile(file, True)
With MC
.Map.Layers.Add(vectorLayer)
.Map.ZoomToExtents()
.Refresh()
End With
End Sub
End Class
view raw Main.vb hosted with ❤ by GitHub

Визуализация:

SharpMap Shapefile Demo
Categories
VB.NET

Решаване на геодезически засечки

Описание:

Това е клас за решаване на геодезически засечки на VB.NET.

Класът включва методи за решаване на права и линейна засечка.

Не е включен метод за решаване на обратна засечка.

Връзки:

Код:

Imports System
Imports System.Math
Public Class PointDetermination
Public Structure Point
Public x, y As Double
End Structure
Public Structure Result
Public x, y As Double
Public m_x, m_y, m_p As Double
End Structure
Private ro As Double = 636.6197
Public Function intersection(ByVal pntA As Point, ByVal pntB As Point, _
ByVal b1 As Double, ByVal b2 As Double, _
ByVal mB As Integer) As Result
Dim angle As Object = New Angle
Dim sap, sbp, c As Double
Dim b3, aap, abp, aab, aba As Double
Dim pntP(2) As Point
Dim res As Result
If pntA.x = pntB.x And pntA.y = pntB.y Then
Throw New Exception(String.Format(My.Resources.equivalentPoints, "A", "B"))
End If
If (b1 + b2) >= 200 Then
Throw New Exception(My.Resources.invalidAngleValue)
End If
If b1 <= 0 Or b2 <= 0 Then
Throw New Exception(My.Resources.invalidAngleValue)
End If
aab = angle.headingAngle(pntB.y - pntA.y, pntB.x - pntA.x)
c = Sqrt(Math.Pow(pntB.y - pntA.y, 2) + Math.Pow(pntB.x - pntA.x, 2))
b3 = 200 - (b1 + b2)
sap = (c * Sin(angle.toRad(b2))) / Sin(angle.toRad(b3))
sbp = (c * Sin(angle.toRad(b1))) / Sin(angle.toRad(b3))
aap = If(aab - b1 < 0, aab - b1 + 400, aab - b1)
aba = If(aab < 200, aab + 200, aab - 200)
abp = If(aba + b2 > 400, aba + b2 - 400, aba + b2)
With pntP(0)
.x = pntA.x + sap * Cos(angle.toRad(aap))
.y = pntA.y + sap * Sin(angle.toRad(aap))
End With
With pntP(1)
.x = pntB.x + sbp * Cos(angle.toRad(abp))
.y = pntB.y + sbp * Sin(angle.toRad(abp))
End With
With res
.x = (pntP(0).x + pntP(1).x) * 0.5
.y = (pntP(0).y + pntP(1).y) * 0.5
.m_x = Nothing
.m_y = Nothing
.m_p = (mB / (ro * Sin(angle.toRad(b3)))) * Sqrt(Math.Pow(sap, 2) + Math.Pow(sbp, 2))
End With
Return res
End Function
Public Function arcSection(ByVal pntA As Point, ByVal pntB As Point, _
ByVal sap As Double, ByVal sbp As Double, _
ByVal a As Double, ByVal b As Double) As Result
Dim angle As Object = New Angle
Dim b1, b2, b3 As Double
Dim aap, abp, aab, aba As Double
Dim dx, dy, s, c As Double
Dim m_s As Double
Dim pntP(2) As Point
Dim res As Result
If pntA.x = pntB.x And pntA.y = pntB.y Then
Throw New Exception(String.Format(My.Resources.equivalentPoints, "A", "B"))
End If
If sap <= 0 Or sbp <= 0 Then
Throw New Exception(My.Resources.negativeOrZeroLengthSide)
End If
If (Sqrt(Math.Pow(pntA.x - pntB.x, 2) + Math.Pow(pntA.y - pntB.y, 2))) >= (sap + sbp) Then
Throw New Exception(My.Resources.notAVerticesOfATriangle)
End If
If (Sqrt(Math.Pow(pntA.x - pntB.x, 2) + Math.Pow(pntA.y - pntB.y, 2)) + sap) <= sbp Then
Throw New Exception(My.Resources.notAVerticesOfATriangle)
End If
If (Sqrt(Math.Pow(pntA.x - pntB.x, 2) + Math.Pow(pntA.y - pntB.y, 2)) + sbp) <= sap Then
Throw New Exception(My.Resources.notAVerticesOfATriangle)
End If
dy = pntB.y - pntA.y
dx = pntB.x - pntA.x
aab = angle.headingAngle(dy, dx)
c = Sqrt(Math.Pow(dy, 2) + Math.Pow(dx, 2))
s = 0.5 * (sap + sbp + c)
b1 = 2 * angle.toGrad(Atan(Sqrt(((s - sap) * (s - c)) / (s * (s - sbp)))))
b2 = 2 * angle.toGrad(Atan(Sqrt(((s - sbp) * (s - c)) / (s * (s - sap)))))
b3 = 2 * angle.toGrad(Atan(Sqrt(((s - sap) * (s - sbp)) / (s * (s - c)))))
aap = If(aab - b1 < 0, aab - b1 + 400, aab - b1)
aba = If(aab < 200, aab + 200, aab - 200)
abp = If(aba + b2 > 400, aba + b2 - 400, aba + b2)
With pntP(0)
.x = pntA.x + sap * Cos(angle.toRad(aap))
.y = pntA.y + sap * Sin(angle.toRad(aap))
End With
With pntP(1)
.x = pntB.x + sbp * Cos(angle.toRad(abp))
.y = pntB.y + sbp * Sin(angle.toRad(abp))
End With
m_s = a + b * (((sap + sbp) * 0.001) * 0.5)
With res
.x = (pntP(0).x + pntP(1).x) * 0.5
.y = (pntP(0).y + pntP(1).y) * 0.5
.m_x = (m_s / Sin(angle.toRad(b3))) * Sqrt(Math.Pow(Sin(angle.toRad(aap)), 2) + Math.Pow(Sin(angle.toRad(abp)), 2))
.m_y = (m_s / Sin(angle.toRad(b3))) * Sqrt(Math.Pow(Cos(angle.toRad(aap)), 2) + Math.Pow(Cos(angle.toRad(abp)), 2))
.m_p = (m_s / Sin(angle.toRad(b3))) * Sqrt(2)
End With
Return res
End Function
End Class